Skip to content

Instantly share code, notes, and snippets.

@jrbalsas
Last active March 23, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrbalsas/c6e9316c9eb70b9f018ea2a5c7079b7c to your computer and use it in GitHub Desktop.
Save jrbalsas/c6e9316c9eb70b9f018ea2a5c7079b7c to your computer and use it in GitHub Desktop.
Cambios para introducir JAX-RS en app SpringMVC
@Path("/clientes")
@Produces(MediaType.APPLICATION_JSON)
//@RequestScoped //No necesario con Spring
public class ClientesRESTService {
@Context
private UriInfo context;
@Autowired //Utilizamos anotaciones de inyección Spring
@Qualifier("clienteDAOList")
ClienteDAO clienteDAO;
//...
}
@ApplicationPath("webservice") // Service URL: /webservice/*
public class ClubJAXRSConfig extends ResourceConfig {
public ClubJAXRSConfig() {
//Location of REST resource classes
packages("com.daw.club.restapi");
}
}
public class ClubWebApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
//IMPORTANT: prevents conflicts between spring and jersey dispatchers: / and /webservice
container.setInitParameter("contextConfigLocation", "<NONE>");
//..
}
}
<!-- Jersey spring dependencies-->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring4</artifactId>
<version>2.27</version>
</dependency>
@jrbalsas
Copy link
Author

Changes needed in a Spring Web application to allow JAX-RS integration, i.e. use dependency injection in JAX-RS services. Changes referred to sample SpringMVC web application

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment