9

Im trying to create an application that access a sql server database using Spring, Maven and Hibernate. When i try to run the application im getting the following error:

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'

Here are my classes

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>

And database.properties

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

(I have blocked the username and passwords just for here), i also have a BeanLocation.xml as well but shouldnt really need to post that up.

Does anyone know how to solve this, its driving me crazy! Thanks

asked Apr 12, 2012 at 11:58
1
  • I think that problem is in your property file location. Do you have in classpath root folder properties and inside database.properties? Commented Apr 12, 2012 at 12:15

2 Answers 2

20

Instead of ${jdbc.driverClassName} in your XML, use ${database.driverClassName}, ie the name of the property used in your database.properties file.

answered Apr 12, 2012 at 12:17
Sign up to request clarification or add additional context in comments.

1 Comment

perfect, that did the trick...i would mark it up but not enough rep to do that yet :/ thanks
2

First you need to ensure that the root location of the config files is accessible under classpath and then, add the relative path of your property file eg. classpath:properties/database.properties

In my case, an additinal issue was an additonal '"' present by mistake that was leading to this error. Hope this helps.

answered Oct 13, 2017 at 15:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.