0 java spring properties javabeans
我正在一个static main方法中创建我的Spring上下文
return new ClassPathXmlApplicationContext("applicationContext.xml");
Run Code Online (Sandbox Code Playgroud)
在里面applicationContext.xml我用我的豆子连线
<bean id="dataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
<property name="driverClassName">
<value>${db.driverclassname}</value>
</property>
...
</bean>
Run Code Online (Sandbox Code Playgroud)
.properties我的类路径上有一个包含值的文件db.driverclassname.
不幸的是我收到以下错误:
Property 'driverClassName' threw exception;
nested exception is java.lang.IllegalStateException:
Could not load JDBC driver class [${db.driverclassname}]
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我正在使用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>
Run Code Online (Sandbox Code Playgroud)
本文详细介绍了用法.