Integrated development of JAX-RS and Spring
1. Build Maven Project
2. Import MAVEN coordinates
<Dependencies> <!--CXF for RS development must be imported - <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-frontend-jaxrs</Artifactid> <version>3.0.1</version> </Dependency> <!--Log Introduction - <Dependency> <groupId>Org.slf4j</groupId> <Artifactid>Slf4j-log4j12</Artifactid> <version>1.7.12</version> </Dependency> <!--Client - <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-rs-client</Artifactid> <version>3.0.1</version> </Dependency> <!--extending the JSON provider - <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-rs-extension-providers</Artifactid> <version>3.0.1</version> </Dependency> <!--convert JSON toolkit to be extension providers dependent - <Dependency> <groupId>Org.codehaus.jettison</groupId> <Artifactid>Jettison</Artifactid> <version>1.3.7</version> </Dependency> <!--Spring Core - <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-context</Artifactid> <version>4.1.7.RELEASE</version> </Dependency> <!--Spring Web Integration - <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-web</Artifactid> <version>4.1.7.RELEASE</version> </Dependency> <!--Spring consolidates JUnit - <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-test</Artifactid> <version>4.1.7.RELEASE</version> </Dependency> <!--JUnit Development Package - <Dependency> <groupId>Junit</groupId> <Artifactid>Junit</Artifactid> <version>4.12</version> </Dependency> </Dependencies>
3. Configure Web. xml
<!--Spring configuration file Location - <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:applicationContext.xml</Param-value> </Context-param> <!--Spring Core Listener - <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <servlet> <Servlet-name>Cxfservice</Servlet-name> <Servlet-class>Org.apache.cxf.transport.servlet.CXFServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Cxfservice</Servlet-name> <Url-pattern>/services/*</Url-pattern> </servlet-mapping>
4. Writing entity classes and service
5. Configure the Release RS service in Applicationcontext.xml
<!--Address Publishing Service addresses Servicesbeans service implementation class-<jaxrs:server id="UserService"address="/userservice"> <jaxrs:serviceBeans> <beanclass="Cn.itcast.cxf.service.UserServiceImpl"/> </jaxrs:serviceBeans> <jaxrs:inInterceptors> <beanclass="Org.apache.cxf.interceptor.LoggingInInterceptor"/> </jaxrs:inInterceptors> <jaxrs:outInterceptors> <beanclass="Org.apache.cxf.interceptor.LoggingOutInterceptor"/> </jaxrs:outInterceptors> </jaxrs:server>
6. Configure the service startup port
<Build> <Plugins> <plugin> <groupId>Org.codehaus.mojo</groupId> <Artifactid>Tomcat-maven-plugin</Artifactid> <version>1.1</version> <Configuration> <Port>9996</Port> </Configuration> </plugin> </Plugins> </Build>
Integrated development of JAX-RS and Spring