maven项目无法读取配置文件

Spring-mvc

<!-- 配置文件 -->
<bean id="configProperty"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:setting.properties</value>
</list>
</property>
</bean>

<!-- 配置信息 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="false" />
<property name="properties" value="configProperty" />
</bean>


Spring-Mybatis

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="false">
<property name="driverClassName">
<value>${db.driver}</value>
</property>
<property name="url">
<value>${db.url}</value>
</property>
<property name="username">
<value>${db.username}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
<property name="initialSize">
<value>5</value>
</property>
<property name="maxTotal">
<value>50</value>
</property>
<property name="maxWaitMillis">
<value>60000</value>
</property>
<property name="maxIdle">
<value>20</value>
</property>
<property name="connectionProperties">
<value>clientEncoding=UTF-8</value>
</property>
</bean>

<!-- 创建 sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>

setting.properties

db.driver=com.mysql.jdbc.Driver

db.url=jdbc:mysql://localhost:3306/live?useUnicode=true&characterEncoding=utf-8

db.username=root

db.password=root

eclipse 报错

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [spring-mybatis.xml]: Could not resolve placeholder 'db.driver' in string value "${db.driver}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'db.driver' in string value "${db.driver}"

远飞的小马
浏览 4499回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java