Jersey 2 + Spring: @Autowired - null

I am trying to use Jersey 2 with Spring with this article: How to use Jersey 2 with Spring IoC container

But the autwired bean is null when the application tries to call it after a client request. In applicationContext.xml, I have only component scan .

In pom.xml: 
<spring.version>4.1.0.RELEASE</spring.version>
<jersey.version>2.12</jersey.version>

@Component
@RequestScoped
@Path("/user")
public class UserREST {
    @Autowired
    private UserFacade userFacade;

    @POST
    @Path("/auth")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({MediaType.APPLICATION_JSON})
    public AuthResponse authorize(User user){
        return userFacade.authorize(user);  // Null is caught here
    }
}

-

@Component
public class UserFacade {

    public AuthResponse authorize(com.pushock.model.User user){
        AuthResponse response = new AuthResponse();
        response.setAuthorized(true);
        return response;
    }
}

What am I doing wrong?

UPD: Here is my pom.xml https://bitbucket.org/spukhov/memo-ws/src/00724e00e3aa786f62fd0e43fe0606de6ae569df/pom.xml?at=master

+3
source share
2 answers

Spring beans JAX-RS, Jersey Spring.

maven, pom.xml

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.12</version>
</dependency>

: 22. Spring DI Spring Github.

, , , , Spring. web.xml

   <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
+9

java- spring, :

servletContext.setInitParameter("contextConfigLocation", "<NONE>");

WebApplicationInitializer

+1

Source: https://habr.com/ru/post/1616789/


All Articles