Created
September 7, 2014 20:35
-
-
Save zachlendon/3868bb34abe451545c15 to your computer and use it in GitHub Desktop.
Spring + Jersey
This file contains hidden or 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
| package com.hotelone.rs.resources | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.Produces; | |
| import javax.ws.rs.core.MediaType; | |
| @Path("/ws") | |
| @Component | |
| public class HelloWorldResource { | |
| @Autowired | |
| private HelloWorldService helloWorldService; | |
| @GET | |
| @Path("hello") | |
| @Produces(MediaType.TEXT_PLAIN) | |
| public String hello(){ | |
| return helloWorldService.sayHello(); //returns "hello" | |
| } | |
| public TestBean getHelloWorldService() { | |
| return helloWorldService; | |
| } | |
| public void setHelloWorldService(HelloWorldService helloWorldService) { | |
| this.helloWorldService = helloWorldService; | |
| } | |
| } |
This file contains hidden or 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
| package com.hotelone.rs; | |
| import org.glassfish.jersey.server.ResourceConfig; | |
| import org.glassfish.jersey.server.spring.scope.RequestContextFilter; | |
| public class MyApplication extends ResourceConfig { | |
| public MyApplication () { | |
| register(RequestContextFilter.class); | |
| this.packages("com.hotelone.rs.resources"); | |
| } | |
| } | |
This file contains hidden or 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
| <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | |
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | |
| version="3.1"> | |
| <context-param> | |
| <param-name>contextConfigLocation</param-name> | |
| <param-value>/WEB-INF/applicationContext.xml</param-value> | |
| </context-param> | |
| <listener> | |
| <listener-class>org.springframework.web.context.ContextLoaderListener | |
| </listener-class> | |
| </listener> | |
| <listener> | |
| <listener-class>org.springframework.web.context.request.RequestContextListener | |
| </listener-class> | |
| </listener> | |
| <listener> | |
| <listener-class>org.springframework.web.context.ContextLoaderListener | |
| </listener-class> | |
| </listener> | |
| <servlet> | |
| <servlet-name>javax.ws.rs.core.Application</servlet-name> | |
| <servlet-class>org.glassfish.jersey.servlet.ServletContainer | |
| </servlet-class> | |
| <init-param> | |
| <param-name>javax.ws.rs.Application</param-name> | |
| <param-value>com.hotelone.rs.MyApplication</param-value> | |
| </init-param> | |
| <load-on-startup>1</load-on-startup> | |
| </servlet> | |
| <servlet-mapping> | |
| <servlet-name>javax.ws.rs.core.Application</servlet-name> | |
| <url-pattern>/*</url-pattern> | |
| </servlet-mapping> | |
| <filter> | |
| <filter-name>characterEncodingFilter</filter-name> | |
| <filter-class>org.springframework.web.filter.CharacterEncodingFilter | |
| </filter-class> | |
| <init-param> | |
| <param-name>encoding</param-name> | |
| <param-value>UTF-8</param-value> | |
| </init-param> | |
| <init-param> | |
| <param-name>forceEncoding</param-name> | |
| <param-value>true</param-value> | |
| </init-param> | |
| </filter> | |
| </web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment