java - How to make autowire object initialized in ApplicationListener? - Stack Overflow
First you are using the singleton pattern which I would say is an anti-pattern especially when combined with auto wiring.
Second in your getInstance()
method you are creating a new instance of AppContext
yourself. This instance isn't managed by Spring so @Autowired
is pretty much useless here, Spring is only able to inject dependencies into beans it knows about.
Instead make your AppContext
a component (or service what ever you like). Remove the getInstance
method and use constructor injection instead.
Read full article from java - How to make autowire object initialized in ApplicationListener? - Stack Overflow
No comments:
Post a Comment