2012-04-12 4 views
2

Spring、Maven、およびHibernateを使用してSQL Serverデータベースにアクセスするアプリケーションを作成しようとしています。私は次のエラーを取得したアプリケーションのイムを実行しようとすると:ここクラスパスのリソース[spring/database/DataSource.xml]に 'dataSource'という名前のBean定義が定義されていません

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' 

は私のクラス

DataSoucre.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> 

あるHibernate.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> 

そしてデータベース.properties

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

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

誰かがこれを解決する方法を知っていますか、それは私を夢中にさせます! おかげで、あなたのXMLで

+0

私はその問題があなたの財産であると思います。ファイルの場所。クラスパスのルートフォルダのプロパティとdatabase.properties内にはありますか? – chalimartines

答えて

11

代わりの${jdbc.driverClassName}${database.driverClassName}を使用するには、あなたのdatabase.propertiesファイルで使用されるプロパティの名前、すなわち。

+0

完璧な、それはトリックでした...私はそれをマークするが、まだそれを行うのに十分な担当者ではない:/ありがとう – newSpringer

0

まず、クラスパスの下で設定ファイルのルートの場所にアクセスできるようにしてから、プロパティファイルの相対パスを追加する必要があります。 クラスパス:私の場合はプロパティ/ database.properties

を、additinal問題は、このエラーにリードしていた誤ってのadditonal「"」存在したこの情報がお役に立てば幸い

関連する問題