我正在使用 Spring Boot AutoConfiguration 来注册 bean。需要找到一种方法,通过它我可以将通过 Auto-Configuration 配置的 bean 注册为 Rest Controller
SampleController.java
public class SampleController
{
@GetMapping("/sample-path")
public String sampleMethod()
{
return "Sample String";
}
}
SampleControllerAutoConfiguration.java
@Configuration
@ConditionalOnProperty(value = "some.property", havingValue = "true") // using this property, the parent app may or may not chose to have the Controller Endpoint
public class SampleControllerAutoConfiguration
{
// Need to register this bean as a controller
@Bean
@ConditionalOnMissingBean
public SampleController sampleController()
{
return new SampleController();
}
}
我无法注释SampleController,@RestController因为它与导入它的父项目在同一个包中,因此由于组件扫描而自动配置