Spring+SpringMVC+MyBatis 踩坑记录
最近在公司实习部门负责的项目和小学期都用到了SSM架构来开发,因此这里记录一些遇到的坑,以及解决办法
Could not resolve placeholder “mail.from” in string value “${mail.from}
出现原因
在工程中创建了两个properties文件,如jdbc.properties和mail.properties文件并且同时导入发生。
解决方案
- 文件导入写到一个配置中,中间加逗号隔开
1
| <context: property-placeholder location="classpath:jdbc.properties , classpath:mail.properties"/>
|
- 在每个扫描的配置文件后加上 ignore-unresolvable=”true”
1 2 3 4
| <context: property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />
<context: property-placeholder location="classpath:mail.properties" ignore-unresolvable="true" />
|
- 使用PropertiesFactoryBean管理配置文件
1 2 3 4 5 6 7 8 9 10 11 12
| <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> <value>classpath:mail.properties</value> </list> </property> <property name="fileEncoding" value="UTF-8"/> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="properties" ref="configProperties"/> </bean>
|