应用配置:
@Configuration
@ComponentScan(basePackages = {"configuration", "nsd"}) //<- base packages here
public class ApplicationConfiguration {
}
应用程序属性:
@Component
@EnableConfigurationProperties
public class ApplicationProperties {
...
我的休息控制器:
@RestController
public class MyRestController {
@Autowired
private ApplicationProperties properties; // <-- could not autowire
...
当我启动应用程序时,我看到:
****************************** 应用程序无法启动
描述:
nsd.MyRestController 中的字段属性需要一个无法找到的“configuration.ApplicationProperties”类型的 bean。
行动:
考虑在你的配置中定义一个“configuration.ApplicationProperties”类型的bean。
我不明白为什么。ComponentScan 在配置类中提供。
如何解决这个问题?
更新
如果将 ApplicationProperties 移动到nsd
包 - 上下文正确,但我仍然不明白为什么它不能从旧包中工作