在我的Spring Web Application(Spring版本 - 4.2)中,我试图将Hibernate 5.1连接到MySQL数据库。但我在Tomcat启动时遇到以下错误
org.springframework.beans.factory.BeanCreationException:错误 在ServletContext中定义名为'sessionFactory'的bean resource [/WEB-INF/dispatcher-servlet.xml]:调用init 方法失败;嵌套异常是 org.hibernate.tool.schema.spi.SchemaManagementException:无法 获取JDBC连接
请帮我解决这个问题!
这是我的DataSource
Bean和sessionFactory
Bean
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
<property name="initialSize" value="1"/>
<property name="maxActive" value="10"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.testproject.hibernate.entity"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
</props>
</property>
</bean>