Java Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]:

HI I'm following a youtube tutorial , https://www.youtube.com/watch?v=rdYQOqxq9F0 Add,Edit,Delete,Search using Spring and Hibernate

getting this error,

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Could not resolve placeholder 'jdbc.driverClassName'

file: jdbc.properties

jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://localhost:3306/StudentDB
jdbc.username=root
jdbc.password=admin

file:spring-servlet.xml

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>

Answers


You don't seem to have a property named jdbc.driverClassName in your properties file.

It should probably be

jdbc.driverClassName=com.mysql.jdbc.Driver

you have committed mistake in these lines

 p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"

compare your jdbc.properties file in your directory.

example jdbc.properties content:

Dialect=org.hibernate.dialect.MySQLDialect// for jdbc use this. Driver=com.mysql.jdbc.Driver
Url=jdbc:mysql://localhost:3306/StudentDB
Username=root
Password=root

In ApplicationContext.xml, it should be like this

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="${Dialect}"
    p:url="${Url}"
    p:username="${Username}"
    p:password="${Password}" />

Need Your Help

Where can I find a C# class for "Shamir's Secret Sharing"?

c# .net security

I am trying to find a class or something that would allow me to do Shamir's Secret Sharing.