Jersey initialization Configuration

Source: Internet
Author: User
Tags glassfish

An actual project configuration

Company VIP platform because of the particularity of business, the operation of business data, as well as the front-end decoupling and other requirements, the use of the Jersey framework. The spring framework is also used.

Two jersey initialization

Configure the Web project configuration file xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version= "3.0" > <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-l ist> <display-name>vipmanager</display-name> <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>
<!--configuration jersey can use the servlet's AP and specify the initialized custom class i--> <servlet> <servlet-name>jersey-servlet</servlet -name> <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <para M-value>com.timevale.esign.vip.application.myapplication</param-value> </init-param> <load -on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey- Servlet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <!--<filter> <filter-name>accessse Rvlet</filter-name> <filter-class>com.timevale.esign.vip.intercept.accessservlet</filter-class& Gt </filter> <filter-mapping> <filter-name>AccessServlet</filter-name> <url -pattern>/content/acc.jsp</url-pattern> </filter-mapping> <filter> <filter- Name>restaccessservlet</filter-name> <filter-class> Com.timevale.esign.vip.intercept.restaccessservlet</filter-class> </filter> <filter-mapping> <filter-name>RestAccessServlet</filter-name> <URL-PATTERN>/REST/API/*</URL-PATTERN&G T </filter-mapping>--></web-app>

Jersey initializing the Startup class

/*** Hangzhou Tian Gu Information Technology Co., Ltd. source code, copyright Hangzhou Tian Gu Information Technology Co., Ltd. <br/> * Project name: Openapi-tech Maven Webapp <br/> * File name: Myapplication.java <br/> * Package: com.timevale.esign.openapi.tech.application <br/> * Description: TODO <br/> * Revision history: <br/> * 1. [October 9, 2015 5:24:40] Create file by jsh*/ Packagecom.timevale.esign.vip.application;ImportJavax.ws.rs.ApplicationPath;ImportOrg.glassfish.jersey.server.ResourceConfig;ImportOrg.glassfish.jersey.server.spring.scope.RequestContextFilter;ImportCom.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;/*** Class Name: Myapplication.java <br/> * Function Description: VIP Project Jersey Initialize startup class <br/> * Modify History: <br/> * 1. [October 9, 2015 5:24:40] Create class by Jsh*/@ApplicationPath ("/rest") Public classMyApplicationextendsResourceConfig {/*** MyApplication Construction method*/     PublicMyApplication () {//initializes the resource, initialized in the form of a specified package, separated by semicolons between multiple packagesPackages ("Com.timevale.esign.vip.resource"); Packages ("Org.glassfish.jersey.examples.multipart"); //Registering Spring filterRegister (Requestcontextfilter.class); //register a data converter that supports automatic conversion between the JSON format and the bean for parameter and return informationRegister (Jacksonjsonprovider.class); //registering for requests that support Multipart-formdata formatRegister (org.glassfish.jersey.media.multipart.MultiPartFeature.class); }}

Jersey initialization Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.