环境切换的目的是 准生产和生产环境切换时,只修改一个文件就可以达到效果

在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 有项目】的更多相关文章

  1. 一分钟学会Spring Boot多环境配置切换

    一. 问题由来 开发环境.测试环境.生产环境--------我们的软件在不同的环境中,系统参数和配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基本配置,那每次我们将软件部署到 ...

  2. SpringCloud入门之Spring Boot多环境配置切换指南

    在 spring boot 中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量的定义 ...

  3. springboot笔记05——profile多环境配置切换

    前言 一个应用程序从开发到上线,往往需要经历几个阶段,例如开发.测试.上线.每个阶段所用到的环境的配置可能都是不一样的,Springboot 应用可以很方便地在各个环境中对配置进行切换.所以,今天主要 ...

  4. 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. ...

  5. Spring多开发环境配置

    在项目开发中,多环境的的配置可以方便在不同环境的切换,减少错误的产生 一.properties文件的多环境配置 properties文件可以根据不同的后缀来区分不同的环境 application.pr ...

  6. Spring Boot多环境配置

    在项目开发阶段,开发环境和实际生产环境是不一样,比如使用的数据库/服务连接配置等.因此,配置多个开发环境profile还是必要的 多环境的配置(yml)方式 配置其实很简单,在resource目录下, ...

  7. swagger-ui 系统配置过程(基于spring+springmvc+swagger+springfox配置 web-api 管理系统)

    web工程部分框架信息:spring springmvc swagger springfox maven 参考文档:https://www.cnblogs.com/exmyth/p/7183753.h ...

  8. 嗯,挺全乎儿的,Spring Boot 多环境配置都在这里了,你喜欢哪种?

    持续原创输出,点击上方蓝字关注我 目录 前言 Spring Boot 自带的多环境配置 创建不同环境的配置文件 指定运行的环境 Maven 的多环境配置 创建多环境配置文件 定义激活的变量 pom 文 ...

  9. Java开发学习(三十二)----Maven多环境配置切换与跳过测试的三种方式

    一.多环境开发 我们平常都是在自己的开发环境进行开发, 当开发完成后,需要把开发的功能部署到测试环境供测试人员进行测试使用, 等测试人员测试通过后,我们会将项目部署到生成环境上线使用. 这个时候就有一 ...

随机推荐

  1. vue 项目部署后 刷新一下 页面找不到 解决

    1.修改配置router的参数  (效果不好) 2. (不能解决 出现403) 后端配置例子 Apache <IfModule mod_rewrite.c> RewriteEngine O ...

  2. python 文件移动

    python实现文件移动: import shutil shutil.move("original_path", "new_folder") # move fi ...

  3. JAVA NIO学习记录2-非阻塞式网络通信

    一.阻塞与非阻塞 传统的IO 流都是阻塞式的.也就是说,当一个线程调用read() 或write() 时,该线程被阻塞,直到有一些数据被读取或写入,该线程在此期间不能执行其他任务.因此,在完成网络通信 ...

  4. 数据恢复软件extundelete介绍

    linux下文件系统一般由文件名.Inode.Block三部分组成.当一个用户在Linux系统中试图访问一个文件时,系统会先根据文件名去查找它的inode,看该用户是否具有访问这个文件的权限.如果有, ...

  5. 关闭IPV6

    [root@bgw-t ~]# cat > /etc/modprobe.d/ipv6.conf << EOF alias net-pf-10 off options ipv6 dis ...

  6. 协变(covariance),逆变(contravariance)与不变(invariance)

    协变,逆变与不变 能在使用父类型的场景中改用子类型的被称为协变. 能在使用子类型的场景中改用父类型的被称为逆变. 不能做到以上两点的被称为不变. 以上的场景通常包括数组,继承和泛型. 协变逆变与泛型( ...

  7. MongoDB 集合命令

    集合命令 创建语法如下 name是要创建的集合的名称 options是一个文档,用于指定集合的配置,选项​​参数是可选的,所以只需要到指定的集合名称 可以不手动创建集合,向不存在的集合中第一次加入数据 ...

  8. 大型运输行业实战_day05_1_登录+注销+表单重复提交+登录拦截器

    1.登录 登录实现如下步骤: 1.在首页中添加登录按钮 html代码如下: <%@ page contentType="text/html;charset=UTF-8" la ...

  9. cdoj844-程序设计竞赛 (线段树的区间最大连续和)【线段树】

    http://acm.uestc.edu.cn/#/problem/show/844 程序设计竞赛 Time Limit: 3000/1000MS (Java/Others)     Memory L ...

  10. android mapView

    1.Because the Maps library is not a part of the standard Android library, you must declare it in the ...