主类中的Spring-Boot @Autowired变为空

主类中的Spring-Boot @Autowired变为空,第1张

主类中的Spring-Boot @Autowired变为空

onStartup
是在应用程序生命周期的早期由servlet容器调用的,并且是在由servlet容器而不是Spring
Boot创建的类的实例上调用的。这就是为什么
jmsTopicListener
null

onStartup
可以使用注解的方法代替覆盖
@PostConstruct
。一旦创建了实例
Application

注入了任何依赖项,它将被Spring调用:

@SpringBootApplication@ComponentScan({"com.mainpack", "com.msgpack.jms"})@EnableJmspublic class Application extends SpringBootServletInitializer {    @Autowired    private JmsTopicListener jmsTopicListener;    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(Application.class);    }    @PostConstruct    public void listen() {         jmsTopicListener.listenMessage();    }    public static void main(String[] args) {        ApplicationContext context = SpringApplication.run(Application.class, args);        LogService.info(Application.class.getName(), "Service Started...");    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5122744.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存