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

在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. vscode 习惯配置

    { "gitlens.advanced.messages": { "suppressShowKeyBindingsNotice": true }, " ...

  2. 【干货】国外程序员整理的 C++ 资源大全(转)

    转zi:http://www.csdn.net/article/2014-10-24/2822269-c++ 关于 C++ 框架.库和资源的一些汇总列表,由 fffaraz发起和维护. 内容包括:标准 ...

  3. Nginx 反向代理、后端检测模块

    简介: Nginx 反向代理模块:ngx_http_proxy_module.ngx_http_upstream_module 后端检测模块:nginx_http_upstream_check_mod ...

  4. 通过python构建集中式的病毒扫描机制

    Clam AntiVirus(Clam AV)是一个免费而且开放源码的防毒软件,软件与病毒库的更新由开源社区免费发布,目前ClamdAV主要为Linux.Uinux系统提供病毒扫描查杀pyClamad ...

  5. Haskell语言学习笔记(31)ListT

    Control.Monad.Trans.List 标准库中的 ListT 的实现由于有 bug,已经被废弃. list-t 模块 这里使用 list-t 模块中的 ListT. list-t 模块需要 ...

  6. CNN深度好文

    https://www.zhihu.com/question/52668301/answer/194998098?utm_medium=social&utm_source=qq

  7. gtftools软件简单介绍(我自己不建议用,因为我发现不好用)

    1)背景 生物信息学研究经常涉及计算或提取基因的各种特征,如基因ID作图,GC含量计算和不同类型的基因长度,通过操纵基因模型,这些模型通常以GTF格式注释,可从ENSEMBL或GENCODE数据库获得 ...

  8. 华为手机不打印log解决方法

    在拨号界面输入:*#*#2846579#*#*    进入后台设置---log设置---开启AP日志...开关即可

  9. easyUIDataGrid分页

    package com.cn.eport.util; import java.util.List; /** * * * @author zh * */ public class DataGrid im ...

  10. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...