@Autowired is not working with jersey and spring

后端 未结 4 845
攒了一身酷
攒了一身酷 2021-01-28 09:37

When I am running test at that time @Autowired is working but when I run the web app and try to fetch data at that time its throwing null pointer exception.

4条回答
  •  不知归路
    2021-01-28 09:54

    You can try using the SpringServlet instead of the jersey provided servlet container to achieve Jersey-Spring integration.

    com.sun.jersey.spi.spring.container.servlet.SpringServlet
    

    The documentation for this class states :

    A servlet or filter for deploying root resource classes with Spring integration. This class extends ServletContainer and initiates the WebApplication with a Spring-based IoCComponentProviderFactory, SpringComponentProviderFactory, such that instances of resource and provider classes declared and managed by Spring can be obtained. Classes of Spring beans declared using XML-based configuration or auto-wire-based confguration will be automatically registered if such classes are root resource classes or provider classes. It is not necessary to provide initialization parameters for declaring classes in the web.xml unless a mixture of Spring-managed and Jersey- managed classes is required. The servlet supports configuration of child applicationContexts, see CONTEXT_CONFIG_LOCATION.

提交回复
热议问题