HI I'm following a youtube tutorial , https://www.youtube.com/watch?v=rdYQOqxq9F0 Add,Edit,Delete,Search using Spring and Hibernate
嗨,我正在学习youtube教程,https://www.youtube.com/watch?使用Spring和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.properties
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://localhost:3306/StudentDB
jdbc.username=root
jdbc.password=admin
file:spring-servlet.xml
文件: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>
2 个解决方案
#1
3
You don't seem to have a property named jdbc.driverClassName
in your properties file.
您似乎没有一个名为jdbc的属性。在属性文件中的driverClassName。
It should probably be
它应该是
jdbc.driverClassName=com.mysql.jdbc.Driver
#2
2
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.
比较你的jdbc。属性文件在您的目录中。
example jdbc.properties content:
jdbc示例。属性内容:
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
在ApplicationContext。xml,应该是这样的。
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${Dialect}"
p:url="${Url}"
p:username="${Username}"
p:password="${Password}" />
#1
3
You don't seem to have a property named jdbc.driverClassName
in your properties file.
您似乎没有一个名为jdbc的属性。在属性文件中的driverClassName。
It should probably be
它应该是
jdbc.driverClassName=com.mysql.jdbc.Driver
#2
2
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.
比较你的jdbc。属性文件在您的目录中。
example jdbc.properties content:
jdbc示例。属性内容:
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
在ApplicationContext。xml,应该是这样的。
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${Dialect}"
p:url="${Url}"
p:username="${Username}"
p:password="${Password}" />