Spring Boot:未创建控制器Bean

o2g1uqev  于 2023-03-02  发布在  Spring
关注(0)|答案(1)|浏览(162)

我已经创建了一个简单的Spring引导应用程序,它只有一个API,但是这个API并不向用户公开。
我使用的是java版本17。 Spring 启动:3.0.3
请找到我的代码

    • 主计长**
package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/test")
    public String test(){
        return "test";
    }
}
    • 主应用程序**
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
    • 应用程序.属性**
server.port=8081
management.endpoints.web.base-path=/
management.endpoints.web.exposure.include=*
    • 生成分级**
plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.3'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

在调试过程中,我添加了执行器,并点击了API/mappings和/beans,注意到我的**/testAPI不在mappings列表中,并且在beans列表中没有找到我的控制器的beanTestController**。

rjee0c15

rjee0c151#

@SpringBootApplication(扫描基础包= {“com.示例.包”},排除={Controller.class}),在主类中使用此

相关问题