【发布时间】:2020-10-21 17:55:09
【问题描述】:
在我的项目中,我使用了带有注解的@Configuration、@EnableAutoConfiguration、@ComponentScan 和 ImportResource 配置。我没有使用@SpringBootApplication,但应用程序在没有@SpringBootApplication 注解的情况下成功构建。我不明白为什么没有调用@RestController 类?
@Configuration
@EnableAutoConfiguration(exclude = {
//removed default db config
DataSourceAutoConfiguration.class, XADataSourceAutoConfiguration.class})
@ComponentScan(basePackages = { "com.test.debasish.dummy" }, excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = Test.class))})
@ImportResource( value = {"classpath*:*beans*.xml"})
public class TestApplication{
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
@RestController
public class TestController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@GetMapping("/test")
@ResponseBody
public Greeting getResource(@RequestParam(name="name", required=false, defaultValue="Stranger") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}
【问题讨论】:
-
请阅读sping boot架构更多细节
标签: spring-boot rest spring-mvc spring-security spring-boot-actuator