8

Spring、Maven、および Hibernate を使用して SQL Server データベースにアクセスするアプリケーションを作成しようとしています。アプリケーションを実行しようとすると、次のエラーが発生します。

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in class path resource [spring/database/DataSource.xml]: Could not resolve placeholder 'jdbc.driverClassName'

ここに私のクラスがあります

データソース.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
    <value>/properties/database.properties</value>
</property>
</bean>

<bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

</beans>

休止状態.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- Hibernate session factory -->
<bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
  <ref bean="dataSource"/>
</property>

<property name="hibernateProperties">
   <props>
     <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
     <prop key="hibernate.show_sql">true</prop>
   </props>
</property>

<property name="annotatedClasses">
<list>
    <value>com.fexco.helloworld.web.model.Customer</value>
</list>
</property>

</bean>
</beans>

および database.properties

database.driverClassName=net.sourceforge.jtds.jdbc.Driver
database.url=jdbc:jtds:sqlserver://localhost:1433;databaseName=Customer
database.username=*****
database.password=*****

(ここだけでユーザー名とパスワードをブロックしました)、BeanLocation.xmlも持っていますが、実際に投稿する必要はありません。

これを解決する方法を知っている人はいますか? ありがとう

4

2 に答える 2

19

${jdbc.driverClassName}XMLの代わりに、${database.driverClassName}を使用します。つまり、database.propertiesファイルで使用されるプロパティの名前です。

于 2012-04-12T12:17:39.057 に答える