在Spring框架写Junit测试类时,引用了两个Spring配置文件:spring-mail.xml和spring-mybatis.xml,两个配置文件中分别引用了Properties:QQMail.properties和estore.properties,在debug Junit时发生了占位符无法识别的错误。
spring-mail相关配置信息如下:
spring-mybatis相关配置信息如下:
测试日志如下:
2015-11-9 14:10:19 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [config/spring-mybatis.xml] 2015-11-9 14:10:19 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [config/spring-mail.xml] 2015-11-9 14:10:19 org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition
信息: Overriding bean definition for bean 'estorePropConfigurer': replacing [Generic bean: class [org.springframework.context.support.PropertySourcesPlaceholderConfigurer]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [config/spring-mybatis.xml]] with [Generic bean: class [org.springframework.context.support.PropertySourcesPlaceholderConfigurer]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [config/spring-mail.xml]] 2015-11-9 14:10:19 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.GenericApplicationContext@a0b1cd0: startup date [Mon Nov 09 14:10:19 CST 2015]; root of context hierarchy 2015-11-9 14:10:20 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
信息: Loading properties file from class path resource [properties/estore.properties] 2015-11-9 14:10:20 org.springframework.test.context.TestContextManager prepareTestInstance
....
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'QQMailAuthenticator' defined in class path resource [config/spring-mail.xml]: Could not resolve placeholder 'Mail.username' in string value "${Mail.username}" ....
日志上在加载estore.properties配置文件后(所属于spring-mybatis.xml),就开始注入spring-mail.xml的bean类,此时QQMail.properties文件(所属于spring-mail.xml)还未加载,理所当然找不到${Mail.username}占位符。
想知道如何控制properties的加载?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
建议使用如下方式:
如果在多个Spring配置文件中声明,需要将配置属性:
ignore-unresolvable="true"
评论
全部评论 (0)