我是spring和hibernate的新手,我正在尝试从spring+hibernate应用程序连接mysql数据库。但不幸的是,我得到下面的错误。试图解决这个问题,但没有得到正确的解决方案。
spring-hibernate版本信息
<properties>
<spring.version>4.2.1.RELEASE</spring.version>
<security.version>4.0.3.RELEASE</security.version>
<jdk.version>1.8</jdk.version>
<hibernate.version>4.3.5.Final</hibernate.version>
<org.aspectj-version>1.7.4</org.aspectj-version>
</properties>
<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<beans:property name="url"
value="jdbc:mysql://localhost:3306/springmvchibernate"/>
<beans:property name="username" value="root" />
<beans:property name="password" value="mysql12345" />
</beans:bean>
<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="annotatedClasses">
<beans:list>
<beans:value>**</beans:value>
</beans:list>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<context:component-scan base-package="org.**" />
<tx:annotation-driven transaction-manager="transactionManager" />
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory"
ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>
消息请求处理失败;嵌套异常为org.springframework.transaction.cannotcreatetransactionexception:无法打开事务的hibernate会话;嵌套异常为org.hibernate.exception.genericjdbception:无法打开连接
说明服务器遇到意外情况,无法完成请求。
例外
org.springframework.web.util.nestedservletexception:请求处理失败;嵌套异常为org.springframework.transaction.cannotcreatetransactionexception:无法打开事务的hibernate会话;嵌套异常为org.hibernate.exception.genericjdbception:无法打开连接org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet)。java:982)org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet。java:861)javax.servlet.http.httpservlet.service(httpservlet)。java:635) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet。java:846)javax.servlet.http.httpservlet.service(httpservlet)。java:742)org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter。java:52)根本原因
org.springframework.transaction.cannotcreatetransactionexception:无法打开事务的hibernate会话;嵌套异常为org.hibernate.exception.genericjdbception:无法打开连接org.springframework.orm.hibernate4.hibernatetransactionmanager.dobegin(hibernatetransactionmanager)。java:544)org.springframework.transaction.support.abstractplatformtransactionmanager.gettransaction(abstractplatformtransactionmanager)。java:373) org.springframework.transaction.interceptor.transactionspectsupport.createtransactionifnecessable(transactionspectsupport。java:427)org.springframework.transaction.interceptor.transactionspectsupport.invokewithintransaction(transactionspectsupport。java:276) org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor。java:96)org.springframework.aop.framework.reflectivemethodinvocation.procedue(reflectivemethodinvocation。java:179)org.springframework.aop.framework.cglibaopproxy$dynamicadvisedinterceptor.intercept(cglibaopproxy。java:653) org.arpit.java2blog.service.countryservice$$enhancerbyspringcglib$$77d6eaf4.getallcountries()org.arpit.java2blog.controller.countrycontroller.getcountries(countrycontroller。java:26)sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl)。java:62) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)java.lang.reflect.method.invoke(方法。java:498)
1条答案
按热度按时间pftdvrlh1#
我得到了这个问题的解决方案我尝试了许多选项更改了hibernate版本,spring版本尝试了所有可能的选项来修复这个问题。经过几个小时的挣扎,我终于发现这是由于mysql连接器版本从5.1.改为8.0.11。它工作得很好。尽管他们在官方文件中提到了以下价值观,但这些价值观是行不通的。
connector/j版本驱动程序类型jdbc版本mysql server版本状态5.1 4 3.0、4.0、4.1、4.2 5.5、5.6、5.7、8.0*推荐版本8.0 4 4.2 5.5、5.6、5.7、8.0开发里程碑