spring3.1.2 容器在实例化属性解析器问题(相同ID覆盖)
2015-08-13 10:35
639 查看
看下项目配置
项目问题: 在注入resourceConfig的时候一直不能为 “rootPath赋上path.properties中的值而是复上了project.root.path字符原因:propertyConfigurer在读取配置文件时没有project.root.path属性所以将{project.root.path} 字符 原因:propertyConfigurer在读取配置文件时没有project.root.path属性所以将{project.root.path}当成文本赋给resourceConfig 项目明明读取了path.properties 为什么会没有project.root.path属性那 因为applicationContext-solr.xml中也配置了个propertyConfigurer实例 spring 在初始化容器的时候会按照在配置文件出现的顺序来初始化容器 而applicationContext-solr.xml在文件后面所以spring用applicationContext-solr.xml中的propertyConfigurer覆盖了当前文件中propertyConfigurer 而applicationContext-solr.xml中的propertyConfigurer只读取了jdbc.properties所以导致出现了此问题。
解决方法: 1.只保留一个propertyConfigurer 2.将想用的propertyConfigurer放到配置文件中的最后让spring用他
注意:项目中如果存在依赖和jar的方式 一定要注意此问题 classpath包括jar 依赖 当前项目的classes 等
<!--为项目自己身的一个属性解析器--> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="locations"> <list> <value>classpath:jdbc.properties</value> <value>classpath:path.properties</value> <value>classpath:solr.properties</value> </list> </property> </bean> <!-- 要实例的类--> <bean id="resourceConfig" class="com.jyt.ResourceConfig"> <property name="rootPath"> <value>${project.root.path}</value> </property> <property name="htmlRelativePath"> <value>html/</value> </property> <property name="pagorRelativePath"> <value>pagor/</value> </property> <property name="jytRootPath"> <value>${jyt.root}</value> </property> </bean> <!-- 引入第三方lib包中的xml--> <import resource="classpath:META-INF/applicationContext-solr.xml"/> <!-- application_sorl.xml--> <!-- 均衡加载sorl url --> <bean id="lbClient" class="org.apache.solr.client.solrj.impl.LBHttpSolrClient"> <constructor-arg name="solrServerUrls" value="${lbClient.url}"/> </bean> <!-- 集群模式下sorl实例 --> <bean id="cloudSolrClient" class="org.apache.solr.client.solrj.impl.CloudSolrClient"> <constructor-arg name="zkHost" value="${cloudSolrClient.url}"/> <constructor-arg name="lbClient" ref="lbClient" /> </bean> <!-- 此处的propertyConfigurer--> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="locations"> <list> <value>classpath:jdbc.properties</value> </list> </property> </bean>
项目问题: 在注入resourceConfig的时候一直不能为 “rootPath赋上path.properties中的值而是复上了project.root.path字符原因:propertyConfigurer在读取配置文件时没有project.root.path属性所以将{project.root.path} 字符 原因:propertyConfigurer在读取配置文件时没有project.root.path属性所以将{project.root.path}当成文本赋给resourceConfig 项目明明读取了path.properties 为什么会没有project.root.path属性那 因为applicationContext-solr.xml中也配置了个propertyConfigurer实例 spring 在初始化容器的时候会按照在配置文件出现的顺序来初始化容器 而applicationContext-solr.xml在文件后面所以spring用applicationContext-solr.xml中的propertyConfigurer覆盖了当前文件中propertyConfigurer 而applicationContext-solr.xml中的propertyConfigurer只读取了jdbc.properties所以导致出现了此问题。
解决方法: 1.只保留一个propertyConfigurer 2.将想用的propertyConfigurer放到配置文件中的最后让spring用他
注意:项目中如果存在依赖和jar的方式 一定要注意此问题 classpath包括jar 依赖 当前项目的classes 等
相关文章推荐
- JVM(java 虚拟机)内存设置
- 一个Spring Boot, JWT,AugularJS接口安全验证的简单例子
- Java学习笔记------一对一聊天功能----
- An internal error occurred during: “Updating Maven Project”. java.lang.NullPointerException
- Java堆、栈、内存分析
- Java 对象的生命周期
- java对象的生命周期及回收
- 递归:整数划分的java编程实现
- 细数JDK里的设计模式
- Spring-Junit4
- Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path
- 浅谈spring中的ioc、工厂模式、单例模式
- Spring依赖注入
- Struts2动态方法调用
- SpringMVC基于代码的配置方式(零配置,无web.xml)
- spring-mybatis.xml配置文件,spring与mybatis整合在一起
- JAVA里生成随机文件名
- java随机生成字符串并排序
- java 导出word乱码问题,99%解决问题
- JAVA 设计模式-单例模式