Spring bean not injected into CXF web service, Why?

后端 未结 3 465
一整个雨季
一整个雨季 2021-01-02 09:22

I am writing a RESTful service (using CXF on JBoss) in which I have inject another class using Spring (Autowired). But the class is not getting injected and is null.

3条回答
  •  余生分开走
    2021-01-02 09:44

    Try to add below method to your web service:

    @PostConstruct
    public void init() {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }
    

    The current web application context (usually the one loaded by ContextLoaderListener) will be used for autowiring, so the IMyCore bean has to be defined in the context listener configuration file and not in the web service one.

提交回复
热议问题