【问题标题】:spring boot @autowired filed injected with null in the @configuration class but worked with @importspring boot @autowired 在@configuration类中注入了null但与@import一起使用
【发布时间】:2016-04-03 07:59:45
【问题描述】:

根据参考using-boot-configuration-classes,我在Application类上使用@ComponentScan,在我的配置类上使用@Configuration,在我的配置类中,我想通过使用@987654324注入其他配置类中定义的bean @ 注释,但是当我运行应用程序时,这些字段为 null,我尝试在应用程序上使用 import 并从配置类中删除 @Configuration,一切正常。

spring boot的bug还是我对@Configuration注解的用法有误解?

【问题讨论】:

  • 你能分享你的代码吗
  • spring boot 没有错误...适用于很多人..可能您的课程布局不正确..请分享您的布局或看看示例..

标签: spring configuration null spring-boot autowired


【解决方案1】:

您是否尝试将其他配置类自动装配到应用程序类中? 在 Spring 创建 Application 类的实例后,使用新方法和 @PostConstruct 使其自动调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多