maven自定义属性给properties文件赋值
来源:互联网 发布:2016漳州市城镇化数据 编辑:程序博客网 时间:2024/04/30 00:16
1、maven的pom文件和主pom文件要配置相关插件和资源路径
编译插件:maven-compiler-plugin
资源插件:maven-resources-plugin
配置资源路径:resources,指向到相关需要覆盖的路径(properties文件所在位置)
<build> <finalName>useradmin-user-webapp</finalName> <resources><resource><directory>${project.basedir}/src/main/resources</directory><filtering>true</filtering><includes><include>**/*</include></includes></resource><resource><directory>${project.basedir}/src/main/webapp/WEB-INF</directory><filtering>true</filtering><includes><include>**/*</include></includes></resource></resources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.5.1</version><configuration><source>1.8</source><target>1.8</target><!-- 设置编译的字符集编码和环境编码 --><encoding>UTF-8</encoding><compilerArguments><extdirs>src/main/webapp/WEB-INF/lib</extdirs></compilerArguments></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>2.6</version><configuration><nonFilteredFileExtensions><nonFilteredFileExtension>dat</nonFilteredFileExtension><nonFilteredFileExtension>swf</nonFilteredFileExtension></nonFilteredFileExtensions></configuration></plugin></plugins> </build>pom文件定义maven的自定义属性mvn.pwd
<profiles><profile><id>local</id><activation><activeByDefault>true</activeByDefault></activation><properties> <mvn.pwd>123</mvn.env></properties></profile> </profiles>
password=${mvn.pwd}application的xml文件中加载properties文件
<!-- <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>/WEB-INF/db-mysql.properties</value></list></property></bean> --><!-- <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertiesFactoryBean"><property name="locations"><list><value>/WEB-INF/db-mysql.properties</value></list></property></bean> --><context:property-placeholder location="classpath:db-mysql.properties"ignore-unresolvable="true" />(1)第一种加载properties文件,maven的自定义变量无法赋值到properties中
<!-- <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>/WEB-INF/db-mysql.properties</value></list></property></bean> -->
不建议使用
(2)第二种加载properties文件,如果properties里面变量赋值的是数字,实际它是当作字符串处理
<!-- <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertiesFactoryBean"><property name="locations"><list><value>/WEB-INF/db-mysql.properties</value></list></property></bean> -->
如:
maxWait=1000
该属性变量用到项目中时
如:
<property name="maxWait" value="${maxWait}" />这里name=“maxWait”需要的是int类型,${maxWait}赋值的是数字,会报错类型不对
(3)第三种加载properties文件最好,不会出现其他奇怪的问题
<context:property-placeholder location="classpath:db-mysql.properties"ignore-unresolvable="true" />详细参考:http://blog.csdn.net/nokia_lc/article/details/52084172
3、maven自定义属性、内置属性、pom属性、环境变量属性,都可用于项目中内容赋值
java代码中赋值,利用spring的@value()
@value("mvn.pwd")
String pwd;
properties文件赋值
basepath=${project.basedir}
4、maven也可以获得系统环境变量
${env.JAVA_HOME}
可以获得JAVA_HOME环境变量的内容
阅读全文
0 0
- maven自定义属性给properties文件赋值
- 设计时给自定义web控件的属性赋值
- 创建javaScript自定义对象,并给属性赋值
- Maven中properties属性
- maven项目 修改properties属性文件不用重启
- 使用Spring实现属性文件给常量赋值
- Android 自定义属性赋值
- maven内置属性(${} properties)
- 如何给readonly属性赋值
- JS给对象属性赋值
- Properties属性文件学习
- 读取属性文件*.properties
- 获取属性文件properties
- 操作properties属性文件
- Properties属性文件
- Struts.properties 属性文件
- 操作properties属性文件
- Struts.properties 属性文件
- vue引入Mint-UI
- Linux 远程登录管理工具Putty
- 新侨移民告诉你:为什么要移民新西兰?
- Go实战--golang中使用MongoDB(mgo)
- unity玉石渲染
- maven自定义属性给properties文件赋值
- add
- DeepLearing4J环境配置与开源代码测试
- matlab imresize的用法
- No row with the given identifier exists: [com.device.entity.DcDevice]异常处理
- 用eclipse创建动态web项目手动生成web.xml方法
- 转载csdn
- python爬虫学习多进程下载图片
- matlab imresize 改变图像大小