How to use @Autowired in manually new instance in Spring Boot -


As we know, @ etoward should be used only in instances managed by the spring container. If you have a new instance, and this will not affect the @Autowired member.

But I think in some circumstances, a new example can not escape.

A runnable task such as a DAOS service, which is managed by Spring. Because the job is manually new so I can not use the DASOS service in the threadtask.

So I want to know how to get the application kontax in Spring Boot , and so I want Context.getBean () to bean.

I knew in main () I can automate ApplicationContext. But I can not pass the reference everywhere as a parameter!

I want to get ApplicationContext anywhere.

Any help would be greatly appreciated.

I want to get ApplicationContext anywhere.

This is an anti-pattern, try to avoid it.

Why can not you put your DASCVIVER into something that creates runnable tasks ?


Comments