cxf-rs 、spring 和 swagger 环境配置切换【github 有项目】
2016-08-06 08:17
411 查看
环境切换的目的是 准生产和生产环境切换时,只修改一个文件就可以达到效果
在spring bean 文件中 配置:
在index.jsp 中使用
再进一步:
把"http://localhost:8080/cxf-rs" 值配置到 properties 文件中
spring bean 中
常量文件
使用该常量
完整项目:
git@github.com:witaste/cxf-rs-swagger.git
在spring bean 文件中 配置:
<bean class="cn.zno.common.context.GServletContext"></bean>
package cn.zno.common.context; import java.util.Date; import javax.servlet.ServletContext; import org.springframework.web.context.ServletContextAware; public class GServletContext implements ServletContextAware { private ServletContext servletContext; @Override public void setServletContext(ServletContext servletContext) { this.servletContext=servletContext; getServletContext().setAttribute("resouceVersion", new Date().getTime()); getServletContext().setAttribute("swaggerPath", "http://localhost:8080/cxf-rs-swagger"); } public ServletContext getServletContext() { return servletContext; } }
在index.jsp 中使用
url = "${swaggerPath}/api/swagger.json";
再进一步:
把"http://localhost:8080/cxf-rs" 值配置到 properties 文件中
swagger.path=http://localhost:8080/cxf-rs-swagger
spring bean 中
<util:properties id="config" location="classpath:conf/config.properties"></util:properties>
常量文件
package cn.zno.common.constants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class ApplicationConstants { public static String SWAGGER_PATH; @Autowired(required = true) public void setSWAGGER_PATH(@Value("#{config['swagger.path']}") String SWAGGER_PATH) { ApplicationConstants.SWAGGER_PATH = SWAGGER_PATH; } }
使用该常量
getServletContext().setAttribute("swaggerPath", ApplicationConstants.SWAGGER_PATH);
完整项目:
git@github.com:witaste/cxf-rs-swagger.git
相关文章推荐
- Gradle项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- Maven项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过环境变量设置WEB项目数据源(Spring)及其项目配置文件路径,动态更新数据源及项目配置
- Spring.profile实现开发、测试和生产环境的配置和切换
- Linux环境下Spring Boot项目内置Tomcat参数配置
- Activiti环境配置、项目搭建、与Spring集成、简单示例
- 使用IDEA从零配置springboot项目环境
- Meclispse创建Spring项目并配置框架环境
- 基于spring-mvc模式下的maven-web项目的环境配置
- Spring boot项目maven的profile多环境配置不自动替换变量的问题解决
- WebService-CXF和spring整合实现webservice案例(Spring配置注解环境)
- jbpm使用配置(spring+hibernate+maven项目环境)
- Spring boot 项目 maven的profile多环境配置 不自动替换变量的问题解决
- github上的优秀项目和开发环境配置
- Django项目让本地和服务器环境数据库配置自动切换
- 通过环境变量设置WEB项目数据源(Spring)及其项目配置文件路径,动态更新数据源及项目配置
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Java类中@Profile注解 springboot切换不同环境配置