`
dbp_cn
  • 浏览: 81917 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

spring web.xml中设置变量

    博客分类:
  • java
 
阅读更多

1. spring web.xml注入系统配置属性(如app.properties).

因为web.xml是web系统的配置入库,代码一经编译之后web.xml里面的值就不可改变,不能再程序运行时替换。所以如果需要在web.xml配置属性变量,必须在编译的时候就将属性变量替换。

具体需要在项目新建不同环境的属性文件

 

如(开发文件application-development.properties,测试application-integratetest.properties,生产application-production.properties)。然后在pom文件里面利用mavn profile 指定针对不同环境替换对于的属性文件里的变量,

如下例中有下面变量需要

<filter>
    <filter-name>CAS Authentication Filter</filter-name>
    <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
    <init-param>
      <param-name>casServerLoginUrl</param-name>
      <param-value>${uuc.host}/login</param-value>
    </init-param>
    <init-param>
      <param-name>serverName</param-name>
      <param-value>${server.name}</param-value>
    </init-param>
    <init-param>
      <param-name>gateway</param-name>
      <param-value>false</param-value>
    </init-param>

  

 1. 在application-development.properties等属性文件中配置

uuc.host=http://172.31.52.12:2280/uuc
conf.dir=classpath:
server.name=http://172.31.66.161:4000

 2.在项目的pom.xml 中配置如下build 参数

<build>
	<finalName>ROOT</finalName>
	<defaultGoal>compile</defaultGoal>
	<filters>
		<filter>${filter.file}</filter>
	</filters>
        	<resources>
		<resource>
			<directory>src/main/resources</directory>
			<includes>
				<include>**/*</include>
			</includes>
			<filtering>true</filtering>
		</resource>
		<resource>
			<directory>src/main/resources/properties</directory>
			<includes>
				<include>**/*</include>
			</includes>
			
			<filtering>true</filtering>
		</resource>
	</resources>
</build>
<profiles>
    <!-- 开发 -->
    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <filter.file>src/main/resources/properties/application-development.properties</filter.file>
      </properties>
    </profile>
    <!-- 测试 -->
    <profile>
      <id>test</id>
      <properties>
        <filter.file>src/main/resources/properties/application-integratetest.properties</filter.file>
      </properties>
    </profile>
    <!-- 生产 -->
    <profile>
      <id>prod</id>
      <properties>
        <filter.file>src/main/resources/properties/application-production.properties</filter.file>
      </properties>
    </profile>
  </profiles>

 3. maven打包命令使用如下参数即可:

mvn clean install -DskipTests -Pdev (开发)
mvn clean install -DskipTests -Ptest (测试)
mvn clean install -DskipTests -Pprod (生产)

 

分享到:
评论

相关推荐

    Spring 3.x 中文开发手册.pdf

    10、支持Servlet3的某个东东,可以写程序直接启动webapp,而非web.xml,不感兴趣 11、支持servlet3的上传东东,可能是对现有MultipartResolver的加强 12、JPA什么,直接无视 以下都是springmvc的加强,可以注意了 ...

    Spring MVC 入门实例

    因为我的 jsp 和 html 文件都是 UTF-8 编码的, 所以我在 param-value 标签中设置了 UTF-8. 估计你使用的是 GB2312 或者 GBK, 立即转到 UTF-8 上来吧. 分解配置文件. context-param 标签指明我们的配置文件还有 /...

    一个简单的spring mvc实例.docx

    这篇文章将教你快速地上手使用 Spring 框架. 如果你手上有一本《Spring in Action》, 那么你最好从第三部分"Spring 在 Web 层的应用--建立 Web 层"开始看, ... 首先我们需要一个放在 WEB-INF 目录下的 web.xml 文件:

    spring.net中文手册在线版

    22.1.2.向web服务中注入依赖项 22.1.3.将PONO发布为web服务 22.1.4.将AOP代理发布为web服务 22.1.5.客户端的问题 22.2.客户端 22.2.1.WebServiceProxyFactory 22.2.2.WebServiceClientFactory 第二十三章. Windows...

    Spring-Reference_zh_CN(Spring中文参考手册)

    6.4.2. Spring AOP中使用@AspectJ还是XML? 6.5. 混合切面类型 6.6. 代理机制 6.7. 编程方式创建@AspectJ代理 6.8. 在Spring应用中使用AspectJ 6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1....

    使用XFire+Spring构建Web Service

    使用XFire+Spring构建Web Service

    Spring 2.0 开发参考手册

    6.4.2. Spring AOP中使用@AspectJ还是XML? 6.5. 混合切面类型 6.6. 代理机制 6.7. 编程方式创建@AspectJ代理 6.8. 在Spring应用中使用AspectJ 6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 ...

    ssh(structs,spring,hibernate)框架中的上传下载

     由于Spring通过代理Hibernate完成数据层的操作,所以原Hibernate的配置文件hibernate.cfg.xml的信息也转移到Spring的配置文件中:  代码 4 Spring中有关Hibernate的配置信息 1. 2. !-- 数据源的配置 //--> 3. ...

    spring chm文档

    6.4.2. Spring AOP中使用@AspectJ还是XML? 6.5. 混合切面类型 6.6. 代理机制 6.7. 编程方式创建@AspectJ代理 6.8. 在Spring应用中使用AspectJ 6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 ...

    Maven权威指南 很精典的学习教程,比ANT更好用

    本例中所用的技术 7.2. simple-parent项目 7.3. simple-model模块 7.4. simple-weather模块 7.5. simple-persist模块 7.6. simple-webapp模块 7.7. 运行这个Web应用 7.8. simple-command模块 7.9. 运行这...

    spring security 参考手册中文版

    33.3在Tomcat中设置SSL 254 34.运行认证替换 255 34.1概述 255 34.2配置 255 35. Spring Security加密模块 257 35.1简介 257 35.2加密器 257 35.2.1 BytesEncryptor 257 35.2.2 TextEncryptor 258 35.3关键发电机 ...

    springboot学习思维笔记.xmind

    web项目设置在Servlet的context parameter中 事件Application Event 自定义事件,集成ApplicationEvent 定义事件监听器,实现ApplicationListener 使用容器发布事件 Spring高级话题 Spring Aware ...

    Activiti5用户指南(中文版)

    2.2 演示设置 .................................................................................................................................................................... 3 2.3 workspace文件夹...

    spring3.0帮助文档(包含REST资料)

    Spring 3.0重要特性总结如下: ...◆对象/XML映射(OXM):原本在Spring Web服务中提供,现在被纳入Spring框架核心。 ◆下一代计划能力:新的TaskScheduler以及Trigger机制,包含第一类cron支持。

    Java/JavaEE 学习笔记

    第七章 指定运行时变量..................133 第八章 数据模型和数据库设计......134 第九章 Creating Tables(创建表)......135 第十章 Oracle Data Dictionary(数据字典表)........................138 第十一章 ...

    J2EE学习笔记(J2ee初学者必备手册)

    第七章 指定运行时变量..................133 第八章 数据模型和数据库设计......134 第九章 Creating Tables(创建表)......135 第十章 Oracle Data Dictionary(数据字典表)........................138 第十一章 ...

    JAVA核心知识点整理(有效)

    1. 目录 1. 2. 目录 .........................................................................................................................................................1 JVM ........................

Global site tag (gtag.js) - Google Analytics