spring 配置文件使用
来源:互联网 发布:java 节假日判断 编辑:程序博客网 时间:2024/05/17 19:18
配置文件主要是为了方便项目上线后配置信息随时改变,比较灵活。公司使用的paoding rose,和spring大体差不多。
1. 配置文件bean
package com.xx.gamecenter.dashboard.bean;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;/** * @author zexi * @time 2016年10月20日 下午1:41:30 * 用户信息判定文件 */@Componentpublic class FilePathConfig { @Value("#{propertyConfigurer['woman.packagename.file.path']}") private String womanPackageNameFilePath; @Value("#{propertyConfigurer['man.packagename.file.path']}") private String manPackageNameFilePath; @Value("#{propertyConfigurer['student.packagename.file.path']}") private String studentPackageNameFilePath; @Value("#{propertyConfigurer['internetuser.packagename.file.path']}") private String internetuserPackageNameFilePath; public String getWomanPackageNameFilePath() { return womanPackageNameFilePath; } public void setWomanPackageNameFilePath(String womanPackageNameFilePath) { this.womanPackageNameFilePath = womanPackageNameFilePath; } public String getManPackageNameFilePath() { return manPackageNameFilePath; } public void setManPackageNameFilePath(String manPackageNameFilePath) { this.manPackageNameFilePath = manPackageNameFilePath; } public String getStudentPackageNameFilePath() { return studentPackageNameFilePath; } public void setStudentPackageNameFilePath(String studentPackageNameFilePath) { this.studentPackageNameFilePath = studentPackageNameFilePath; } public String getInternetuserPackageNameFilePath() { return internetuserPackageNameFilePath; } public void setInternetuserPackageNameFilePath(String internetuserPackageNameFilePath) { this.internetuserPackageNameFilePath = internetuserPackageNameFilePath; }}
- 配置文件app.properties
woman.packagename.file.path=/data0/test/userInfo_confirm/woman_packageName.txtman.packagename.file.path=/data0/test/userInfo_confirm/man_packageName.txtstudent.packagename.file.path=/data0/test/userInfo_confirm/student_packageName.txtinternetuser.packagename.file.path=/data0/test/userInfo_confirm/internetuser_packageName.txt
- applicationContext.xml设置服务器启动加载配置文件
#单个配置文件写法 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location"> <value>classpath:server.properties</value> </property> <property name="fileEncoding" value="utf-8" /> </bean>
#多个配置文件写法<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:server.properties</value> <value>classpath:app.properties</value> </list> </property> <property name="fileEncoding" value="utf-8" /> </bean>
- 调用配置文件属性
@Autowiredprivate FilePathConfig filePathConfig;filePathConfig.getXXX()调用;
再接再厉!
0 0
- Spring 使用Properties配置文件
- Spring配置文件的使用
- spring 配置文件路径使用
- spring 配置文件使用
- spring的配置文件及使用
- 使用Spring配置文件实现AOP
- 使用Spring配置文件实现事务管理
- Spring中使用多配置文件
- 使用Spring配置文件实现AOP
- Spring 使用Properties配置文件(一)
- Spring 使用Properties配置文件(二)
- 使用spring配置文件实现AOP
- 使用Spring配置文件实现AOP
- 使用dom4j读取spring配置文件
- 使用import简化Spring配置文件
- 使用Spring配置文件实现AOP
- 使用Spring配置文件实现事务管理
- spring使用profile选择配置文件
- ProgressDialog使用总结
- 简单更改样式
- 三种代理模式
- 算法 递归 迭代 阶乘
- 一道概率题
- spring 配置文件使用
- 内存堆和栈的区别
- 针对协议命令字处理函数
- jquery插件 —— Lazy Load 延迟加载图片
- 个人笔记
- 锤子发布会观感
- Storm Trident Internals
- OJ——求值
- 用线性时间复杂度实现找出数组中出现一次的元素