cxf-rs 、spring 和 swagger 环境配置切换【github 有项目】
环境切换的目的是 准生产和生产环境切换时,只修改一个文件就可以达到效果
在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
cxf-rs 、spring 和 swagger 环境配置切换【github 有项目】的更多相关文章
- 一分钟学会Spring Boot多环境配置切换
一. 问题由来 开发环境.测试环境.生产环境--------我们的软件在不同的环境中,系统参数和配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基本配置,那每次我们将软件部署到 ...
- SpringCloud入门之Spring Boot多环境配置切换指南
在 spring boot 中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量的定义 ...
- springboot笔记05——profile多环境配置切换
前言 一个应用程序从开发到上线,往往需要经历几个阶段,例如开发.测试.上线.每个阶段所用到的环境的配置可能都是不一样的,Springboot 应用可以很方便地在各个环境中对配置进行切换.所以,今天主要 ...
- idea spring+springmvc+mybatis环境配置整合详解
idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2. ...
- Spring多开发环境配置
在项目开发中,多环境的的配置可以方便在不同环境的切换,减少错误的产生 一.properties文件的多环境配置 properties文件可以根据不同的后缀来区分不同的环境 application.pr ...
- Spring Boot多环境配置
在项目开发阶段,开发环境和实际生产环境是不一样,比如使用的数据库/服务连接配置等.因此,配置多个开发环境profile还是必要的 多环境的配置(yml)方式 配置其实很简单,在resource目录下, ...
- swagger-ui 系统配置过程(基于spring+springmvc+swagger+springfox配置 web-api 管理系统)
web工程部分框架信息:spring springmvc swagger springfox maven 参考文档:https://www.cnblogs.com/exmyth/p/7183753.h ...
- 嗯,挺全乎儿的,Spring Boot 多环境配置都在这里了,你喜欢哪种?
持续原创输出,点击上方蓝字关注我 目录 前言 Spring Boot 自带的多环境配置 创建不同环境的配置文件 指定运行的环境 Maven 的多环境配置 创建多环境配置文件 定义激活的变量 pom 文 ...
- Java开发学习(三十二)----Maven多环境配置切换与跳过测试的三种方式
一.多环境开发 我们平常都是在自己的开发环境进行开发, 当开发完成后,需要把开发的功能部署到测试环境供测试人员进行测试使用, 等测试人员测试通过后,我们会将项目部署到生成环境上线使用. 这个时候就有一 ...
随机推荐
- Unified shader model
https://en.wikipedia.org/wiki/Unified_shader_model In the field of 3D computer graphics, the Unified ...
- find命令之时间戳使用示例
查看当前目录以及子目录下哪些文件占用的空间最大: find ./ -type f -exec du -m {} \; | sort -nr | head find ./ -type f ...
- unity VideoPlayer
Events(事件) started:在调用play()后立刻调用 prepareCompleted:播放器准备完成时 seekCompleted:缓冲完成时
- [转载]百分之百自动登录2345王牌技术员联盟源代码(delphi)
资源地址:http://download.csdn.net/detail/softlib/9670613
- java 可伸缩阻塞队列实现
最近一年多写的最虐心的代码.必须好好复习java并发了.搞了一晚上终于测试都跑通过了,特此纪念,以资鼓励! import java.util.ArrayList; import java.util.L ...
- System.Data.SqlClient.SqlError: 尚未备份数据库的日志尾部
SQL还原时出现下面的错误,System.Data.SqlClient.SqlError: 尚未备份数据库 "***" 的日志尾部.如果该日志包含您不希望丢失的工作,请使用 BAC ...
- java学习笔记----@Override的作用
初学java或多或少都会有这样的疑问,@Override有什么用,有的时候写,有的时候又不写,搞的初学者甚是郁闷. 做了一两年的开发说起这个问题不一定能够对答如流.小弟才疏学浅,花了点时间,看了一下资 ...
- Python repr() 函数
Python repr() 函数 Python 内置函数 描述 repr() 函数将对象转化为供解释器读取的形式. 语法 以下是 repr() 方法的语法: repr(object) 参数 obje ...
- [SCOI2007]修车(建图好题)
[SCOI2007]修车 https://www.lydsy.com/JudgeOnline/problem.php?id=1070 Time Limit: 1 Sec Memory Limit: ...
- oracle pl/sql程序
简单的pl/sql程序 declare begin dbms_output.put_line('hello world'); end; 什么是PL/SQL? pl/sql(Procedure lang ...