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"