users@jersey.java.net

[Jersey] Re: Try to integrete Jersey with Spring but got null pointer when use autowire to inject

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Mon, 23 Mar 2015 13:50:24 +0100

Hi Liu,

I apologize for delayed response.

From your question, it is not clear what is the AddressClient (i do not see
it configured anywhere) and how is Spring supposed to inject it.

Could you maybe try to put together a more comprehensive test
case application or at least provide the missing information so that
others could help you?

Thanks,

~Jakub

> On 09 Mar 2015, at 13:12, Liu, Ziwei <ziweiliu_at_amazon.com> wrote:
>
> Hello,
>
> I use jersey 2.3 and spring 3.1.
>
> In web.xml
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>/WEB-INF/application-config.xml</param-value>
> </context-param>
> <listener>
> <listener-class>org.springframework.web.context.ContextLoaderListener
> </listener-class>
> </listener>
>
> <servlet>
> <servlet-name>JerseyRESTService</servlet-name>
> <servlet-class>org.glassfish.jersey.servlet.ServletContainer </servlet-class>
> <!-- Register resources and providers under com.amazon.geocoding.console.service package. -->
> <init-param>
> <param-name>javax.ws.rs.Application</param-name>
> <param-value>**.**.RestApplication
> </param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>JerseyRESTService</servlet-name>
> <url-pattern>/rest/*</url-pattern>
> </servlet-mapping>
>
> My RestApplication.java is like this:
> public class RestApplication extends ResourceConfig {
>
> public RestApplication() {
>
> register(RequestContextFilter.class);
> //register JSON converter
> register(JacksonJsonProvider.class);
> //path of service packages
> register(**Service.class);
>
> }
> }
>
> In spring config file
> <context:annotation-config />
> <context:component-scan base-package="**.**.service"/>
>
> In Jersey service file
>
> @Component
> @Path("/service/commons")
> public class **Service {
>
> @Autowired
> private AddressClient addressClient;
>
> but I got null pointer with addressClient.
> Can you help?