spring PropertyPlaceholderConfigurer自定义属性
来源:互联网 发布:阿里云 数梦工场 编辑:程序博客网 时间:2024/06/05 08:36
spring PropertyPlaceholderConfigurer自定义属性
需要继承spring的PropertyPlaceholderConfigurer类
java代码
public class ConfigInitLoadingConfigurer extends PropertyPlaceholderConfigurer { private static final Logger log = LoggerFactory.getLogger(ConfigInitLoadingConfigurer.class); private boolean override = true; private static String[] keyPatterns; private HessianConfigRetrieveServiceImp configRetrieveService = new HessianConfigRetrieveServiceImp(); private HessianConfigRetrieveService selfConfigRetrieveService; private HessianAppRegisterService selfAppRegisterService; private HashMap<String, String> keyMappings = new HashMap(); private List<String> prefixStripKeys = new ArrayList(); private static String appName; private static String appEnv; public void setSelfConfigRetrieveService(HessianConfigRetrieveService selfConfigRetrieveService) { this.selfConfigRetrieveService = selfConfigRetrieveService; } public boolean isOverride() { return this.override; } public void setOverride(boolean override) { this.override = override; } public void setLocalStoreEnabled(boolean enabled) { DynCfgUtil.setLocalStoreEnabled(enabled); } public static String[] getKeyPatterns() { return keyPatterns; } public void setKeyPatterns(String[] keyPatterns) { keyPatterns = keyPatterns; } public HashMap<String, String> getKeyMappings() { return this.keyMappings; } public void setKeyMappings(HashMap<String, String> keyMappings) { this.keyMappings = keyMappings; } public List<String> getPrefixStripKeys() { return this.prefixStripKeys; } public void setPrefixStripKeys(List<String> prefixStripKeys) { this.prefixStripKeys = prefixStripKeys; } public static String getAppName() { if(StringUtils.isBlank(appName)) { appName = getAppNameByProperties(); if(StringUtils.isBlank(appName)) { if(log.isErrorEnabled()) { log.error("参数appName必须配置,不能为空"); } throw new IllegalArgumentException("参数appName必须进行配置"); } } log.info("current app name:" + appName); return appName; } public void setAppName(String appName) { log.info("setAppName name:" + appName); appName = appName; } public static String getAppEnv() { if(StringUtils.isBlank(appEnv)) { log.info("appEnv env is null"); return null; } else { return appEnv; } } public void setAppEnv(String appEnv) { log.info("setAppEnv env:" + appEnv); appEnv = appEnv; } public void setSelfAppRegisterService(HessianAppRegisterService selfAppRegisterService) { this.selfAppRegisterService = selfAppRegisterService; } public ConfigInitLoadingConfigurer() { } }
spring 配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-lazy-init="true"> <import resource="classpath*:/context/acms-client.xml" /> <bean class="com.uns.inf.acms.client.config.ConfigInitLoadingConfigurer" parent="baseConfigurer" lazy-init="false"> <property name="appName" value="app-test" /> <property name="appEnv" value="${env}" /> <property name="prefixStripKeys"> <list> <value>cash.${env}</value> </list> </property> <property name="keyPatterns" value="XXXX,XXX.${env}" /> </bean></beans>
阅读全文
0 0
- spring PropertyPlaceholderConfigurer自定义属性
- Spring PropertyPlaceholderConfigurer 自定义扩展
- Spring自定义PropertyPlaceholderConfigurer
- spring boot 自定义PropertyPlaceholderConfigurer
- Spring自定义PropertyPlaceholderConfigurer
- Spring PropertyPlaceholderConfigurer 自定义扩展
- Spring PropertyPlaceholderConfigurer 自定义扩展
- Spring属性占位符PropertyPlaceholderConfigurer
- Spring属性占位符PropertyPlaceholderConfigurer的使用
- Spring属性占位符PropertyPlaceholderConfigurer的使用
- Spring 属性占位符配置器 PropertyPlaceholderConfigurer
- spring里PropertyPlaceholderConfigurer读取属性文件
- Spring属性占位符PropertyPlaceholderConfigurer的使用
- Spring属性占位符PropertyPlaceholderConfigurer的使用 ${}
- PropertyPlaceholderConfigurer在spring获取属性文件
- Spring属性占位符PropertyPlaceholderConfigurer的使用
- Spring PropertyPlaceholderConfigurer获取属性文件值
- Spring属性占位符PropertyPlaceholderConfigurer的使用
- python基础_0
- 为什么选择drupal?为什么做贡献?怎么学?怎么贡献?
- Android 启动第三方app
- JavaScript 函数
- 简易在线留言板(上)——树洞留言板
- spring PropertyPlaceholderConfigurer自定义属性
- 那什么是外键 外键有什么作用呢
- hdoj 1007 Quoit Design(分治法)
- VS2012程序打包部署详解
- 多进程和多线程
- java默认执行路径
- yum 安装php-fpm+nginx+mysql教程
- 简单的贪吃蛇游戏实现
- struts2 iterator迭代