Cxf-rs, spring, and swagger environment configuration switch "GitHub has projects"

Source: Internet
Author: User

The purpose of the environment switch is to modify only one file to achieve the effect when the production and production environments are switched.

In the spring bean file, configure:

    <class= "Cn.zno.common.context.GServletContext"></Bean  >
 PackageCn.zno.common.context;Importjava.util.Date;ImportJavax.servlet.ServletContext;ImportOrg.springframework.web.context.ServletContextAware; Public classGservletcontextImplementsServletcontextaware {PrivateServletContext ServletContext; @Override Public voidSetservletcontext (ServletContext servletcontext) { This. servletcontext=ServletContext; Getservletcontext (). SetAttribute ("Resouceversion",NewDate (). GetTime ()); Getservletcontext (). SetAttribute ("Swaggerpath", "Http://localhost:8080/cxf-rs-swagger"); }         PublicServletContext Getservletcontext () {returnServletContext; }  }

Use in index.jsp

url = "${swaggerpath}/api/swagger.json";

Further further:

Configure the "Http://localhost:8080/cxf-rs" value in the properties file

Swagger.path=http://localhost:8080/cxf-rs-swagger

In spring beans

<id= "config"  location= "Classpath:conf/config.properties" ></ util:properties >

Constant file

 Packagecn.zno.common.constants;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.beans.factory.annotation.Value;Importorg.springframework.stereotype.Component; @Component Public classapplicationconstants { Public StaticString Swagger_path; @Autowired (Required=true)     Public voidSetswagger_path (@Value ("#{config[' Swagger.path '}") String swagger_path) {Applicationconstants.swagger_path=Swagger_path; }}

Use this constant

Getservletcontext (). SetAttribute ("Swaggerpath", Applicationconstants.swagger_path);

Complete project:

[Email Protected]:witaste/cxf-rs-swagger.git

Cxf-rs, spring, and swagger environment configuration switch "GitHub has projects"

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.