我正在 static main
方法中创建 Spring 上下文
return new ClassPathXmlApplicationContext("applicationContext.xml");
在 applicationContext.xml
中,我正在连接我的一个 bean
<bean id="dataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
<property name="driverClassName">
<value>${db.driverclassname}</value>
</property>
...
</bean>
我的类路径上有一个 .properties
文件,其中包含值 db.driverclassname
。
不幸的是,我收到以下错误:
Property 'driverClassName' threw exception;
nested exception is java.lang.IllegalStateException:
Could not load JDBC driver class [${db.driverclassname}]
我做错了什么?我正在使用 Spring 2.5.5
最佳答案
你不需要PropertyPlaceholderConfigurer吗? ?
例如
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:project.properties</value>
</property>
</bean>
This article详细使用说明。
关于java - Spring 上下文 XML 中的属性未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8821769/