Last active
March 23, 2019 15:14
-
-
Save jrbalsas/c6e9316c9eb70b9f018ea2a5c7079b7c to your computer and use it in GitHub Desktop.
Cambios para introducir JAX-RS en app SpringMVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
//... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationPath("webservice") // Service URL: /webservice/* | |
public class ClubJAXRSConfig extends ResourceConfig { | |
public ClubJAXRSConfig() { | |
//Location of REST resource classes | |
packages("com.daw.club.restapi"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"); | |
//.. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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