简体   繁体   English

无法为事务 JAVA MAVEN SPRING 打开 Hibernate 会话

[英]Could not open Hibernate Session for transaction JAVA MAVEN SPRING

  1. I've seen many replies, and none worked看了很多回复,都没有用
  2. My Config -> Maven / Spring 4 / Hibernate 4 / MySQL 5 / Eclipse Mars / JSF 2 / PrimeFaces 5 / Spring Security我的配置 -> Maven / Spring 4 / Hibernate 4 / MySQL 5 / Eclipse Mars / JSF 2 / PrimeFaces 5 / Spring Security
  3. The solution was working with old depedencies, I did a mvn update:versions and I'm trying to figure out solutions (It was working fine, but can't stand to the idea of every dependency is outdated)解决方案是使用旧的依赖项,我做了一个 mvn update:versions 并且我正在尝试找出解决方案(它工作正常,但无法忍受每个依赖项都已过时的想法)

Here is the error I get after submitting Login form (The whole Tomcat Trace)这是我提交登录表单后得到的错误(整个 Tomcat 跟踪)

août 23, 2015 3:40:28 AM org.apache.catalina.core.ApplicationContext log
INFOS: No Spring WebApplicationInitializer types detected on classpath
août 23, 2015 3:40:28 AM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring root WebApplicationContext
août 23, 2015 3:40:28 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFOS: Root WebApplicationContext: initialization started
août 23, 2015 3:40:29 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFOS: Refreshing Root WebApplicationContext: startup date [Sun Aug 23 03:40:29 WAT 2015]; root of context hierarchy
août 23, 2015 3:40:29 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFOS: Loading XML bean definitions from ServletContext resource [/WEB-INF/application-context.xml]
août 23, 2015 3:40:29 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFOS: Loading XML bean definitions from ServletContext resource [/WEB-INF/security-context.xml]
août 23, 2015 3:40:29 AM org.springframework.security.core.SpringSecurityCoreVersion performVersionChecks
INFOS: You are running with Spring Security Core 4.0.2.RELEASE
août 23, 2015 3:40:29 AM org.springframework.security.config.SecurityNamespaceHandler <init>
INFOS: Spring Security 'config' module version is 4.0.2.RELEASE
août 23, 2015 3:40:29 AM org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser parse
INFOS: Expressions were enabled for method security but no SecurityExpressionHandler was configured. All hasPermision() expressions will evaluate to false.
août 23, 2015 3:40:30 AM org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser parseInterceptUrlsForFilterInvocationRequestMap
INFOS: Creating access control expression attribute 'hasRole('ROLE_MODERATOR')' for /pages/secure/**
août 23, 2015 3:40:30 AM org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser parseInterceptUrlsForFilterInvocationRequestMap
INFOS: Creating access control expression attribute 'permitAll' for /pages/unsecure/**
août 23, 2015 3:40:30 AM org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser parseInterceptUrlsForFilterInvocationRequestMap
INFOS: Creating access control expression attribute 'hasRole('ROLE_MODERATOR')' for /**
août 23, 2015 3:40:30 AM org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser parseInterceptUrlsForFilterInvocationRequestMap
INFOS: Creating access control expression attribute 'permitAll' for /javax.faces.resource/**
août 23, 2015 3:40:30 AM org.springframework.security.config.http.HttpSecurityBeanDefinitionParser checkFilterChainOrder
INFOS: Checking sorted filter chain: [Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 200, Root bean: class [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, Root bean: class [org.springframework.security.web.header.HeaderWriterFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 500, Root bean: class [org.springframework.security.web.csrf.CsrfFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 600, Root bean: class [org.springframework.security.web.authentication.logout.LogoutFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 700, <org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0>, order = 1100, Root bean: class [org.springframework.security.web.authentication.www.BasicAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1500, Root bean: class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1600, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2000, Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2100, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2200, <org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>, order = 2300]
août 23, 2015 3:40:31 AM com.mchange.v2.log.MLog <clinit>
INFOS: MLog clients using java 1.4+ standard logging.
août 23, 2015 3:40:31 AM com.mchange.v2.c3p0.C3P0Registry banner
INFOS: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
août 23, 2015 3:40:32 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.0.Final}
août 23, 2015 3:40:32 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
août 23, 2015 3:40:32 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
août 23, 2015 3:40:32 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
août 23, 2015 3:40:32 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFOS: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge1379bojaf0l1f5utew|a1c6cda, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge1379bojaf0l1f5utew|a1c6cda, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/test, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 2, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
août 23, 2015 3:40:33 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
août 23, 2015 3:40:33 AM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
août 23, 2015 3:40:36 AM org.springframework.security.web.DefaultSecurityFilterChain <init>
INFOS: Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.SecurityContextPersistenceFilter@3f356487, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@45d89c1c, org.springframework.security.web.header.HeaderWriterFilter@6bc624bd, org.springframework.security.web.csrf.CsrfFilter@3e1b9cab, org.springframework.security.web.authentication.logout.LogoutFilter@2a9ed6b3, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@2b278780, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@719ead95, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@138299c9, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4ff5ee44, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@58f96bbd, org.springframework.security.web.session.SessionManagementFilter@5c8f8732, org.springframework.security.web.access.ExceptionTranslationFilter@5b4411bb, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@3ba34359]
août 23, 2015 3:40:36 AM org.springframework.security.config.http.DefaultFilterChainValidator checkLoginPageIsntProtected
INFOS: Checking whether login URL '/pages/unsecure/login.xhtml' is accessible with your configuration
août 23, 2015 3:40:36 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFOS: Root WebApplicationContext: initialization completed in 8304 ms
août 23, 2015 3:40:37 AM com.sun.faces.config.ConfigureListener contextInitialized
INFOS: Initialisation de Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) pour le contexte «/potool»
août 23, 2015 3:40:37 AM com.sun.faces.spi.InjectionProviderFactory createInstance
INFOS: JSF1048 : Présence d’annotations PostConstruct/PreDestroy  Les méthodes de beans gérés marquées avec ces annotations auront des annotations dites traitées.
août 23, 2015 3:40:38 AM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFOS: Monitoring file:/C:/Users/ceo/Desktop/WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/primefaces/WEB-INF/faces-config.xml for modifications
août 23, 2015 3:40:38 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
INFOS: Running on PrimeFaces 5.2
août 23, 2015 3:40:39 AM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-nio-8080"]
août 23, 2015 3:40:39 AM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-nio-8009"]
août 23, 2015 3:40:39 AM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 18107 ms
org.springframework.security.authentication.InternalAuthenticationServiceException: Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext
    at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:125)
    at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:143)
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:167)
    at managedController.LoginBean.login(LoginBean.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:245)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at org.springframework.faces.webflow.FlowActionListener.processAction(FlowActionListener.java:71)
    at org.springframework.faces.model.SelectionTrackingActionListener.processAction(SelectionTrackingActionListener.java:64)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:120)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:544)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:427)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy30.loadUserByUsername(Unknown Source)
    at org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:114)
    ... 81 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext
    at org.springframework.orm.hibernate4.HibernateTransactionManager.isSameConnectionForEntireSession(HibernateTransactionManager.java:711)
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:445)
    ... 89 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContext
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    ... 91 more

Here is my applicationContext :这是我的 applicationContext :

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- Package needed to be scanned for annotation --> <context:component-scan base-package="spring"/> <context:component-scan base-package="spring.dao.CustomerDAO"/> <!-- Use annotation for configuration--> <context:annotation-config/> <context:spring-configured/>

<!-- Data Source Declaration --> <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://localhost/test" />
    <property name="user" value="root" />
    <property name="password" value="" />
    <property name="maxPoolSize" value="2" />
    <property name="maxStatements" value="0" />
    <property name="minPoolSize" value="1" /> </bean>

<!-- Session Factory Declaration --> <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="DataSource" />
    <property name="packagesToScan">
        <list>
            <value>spring.model</value>
            <value>spring.service</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property> </bean>

<!-- Enable the configuration of transactional behavior based on annotations --> <tx:annotation-driven transaction-manager="txManager"/>

<!-- Transaction Manager is defined --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="SessionFactory"/>
     </bean> </beans>

Here is my web.xml :这是我的 web.xml :

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             id="WebApp_ID" version="2.5">
    <display-name>PrimeFaces Web Application</display-name>

    <!-- Spring Security Facelets Tag Library -->
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
    </context-param>

    <!-- Change to "Production" when you are ready to deploy -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <!-- Declare Spring configuration file location -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/application-context.xml
            /WEB-INF/security-context.xml
        </param-value>
    </context-param>

    <!-- Spring -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 <!--   <listener>
          <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener> -->

    <!-- Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Welcome page -->
    <welcome-file-list>
        <welcome-file>faces/pages/secure/login.xhtml</welcome-file>
    </welcome-file-list>

    <!-- JSF mapping -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map these files with JSF -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

The stacktrace indicates that the org.hibernate.engine.transaction.spi.TransactionContext isn't in the web app classpath.堆栈跟踪表明org.hibernate.engine.transaction.spi.TransactionContext不在 Web 应用程序类路径中。 This class is in hibernate-core 4 library.此类位于hibernate-core 4 库中。

There are several ways to include it in the classpath as you can see at the tomcat documentation section Class Loader definitions .有几种方法可以将它包含在类路径中,您可以在tomcat 文档部分类加载器定义中看到。

Due to you are using maven I suggest you to set scope compile for the library dependency to be sure that it will be included in your webapp lib folder.由于您使用的是 maven,我建议您为库依赖项设置范围编译,以确保它将包含在您的 webapp lib 文件夹中。 Check is defined like:检查定义如下:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>4.3.11.Final</version>
  <scope>compile</scope>
</dependency>

Also check the web app has the standard layout folder.还要检查 Web 应用程序是否具有标准布局文件夹。 See here to know how it looks and the final structure of the war package.请参阅此处了解它的外观以及 war 包的最终结构。 Be sure you don't override any configuration related to lib folder in your maven-war-plugin because by default tomcat will look for libraries in WEB-INF/lib folder of war package.确保您没有覆盖与maven-war-plugin 中的lib 文件夹相关的任何配置,因为默认情况下 tomcat 会在 war 包的WEB-INF/lib文件夹中查找库。

I too got the same exception but resolved it with the following configuration.我也遇到了同样的异常,但使用以下配置解决了它。

My POM.xml:我的 POM.xml:

<properties>
        <org.springframework-version>4.2.4.RELEASE</org.springframework-version>
        <hibernate.version>5.0.7.Final</hibernate.version>
</properties>

My servlet-context.xml configuration (Mentioned only hibernate related config):我的 servlet-context.xml 配置(仅提到与休眠相关的配置):

<beans:bean id="hibernate5AnnotatedSessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="annotatedClasses">
            <beans:list>
                <beans:value>your pojo name along with package</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>

    <beans:bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="hibernate5AnnotatedSessionFactory" />
    </beans:bean>  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 休眠会话无法打开进行交易 - Hibernate Session Could not open for transaction CannotCreateTransactionException:无法打开休眠会话进行事务 - CannotCreateTransactionException: Could not open Hibernate Session for transaction 无法为事务打开Hibernate Session,JavaConfig - Could not open Hibernate Session for transaction, JavaConfig 为什么会发生这种“无法打开Hibernate Session进行交易”的情况? - why this “Could not open Hibernate Session for transaction” occured? 首次登录时无法为事务打开休眠会话 - Could not open Hibernate Session for transaction on First Login 无法为事务打开 Hibernate Session; 嵌套异常是无法打开连接 - Could not open Hibernate Session for transaction; nested exception is Could not open connection org.springframework.transaction.CannotCreateTransactionException:无法打开Hibernate Session进行事务处理 - org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction CannotCreateTransactionException:无法打开事务的Hibernate会话(Hibernate,MySQL,MVC) - CannotCreateTransactionException: Could not open Hibernate Session for transaction(Hibernate, MySQL, MVC) SpringMVC和Hibernate:CannotCreateTransactionException:无法打开Hibernate Session进行事务处理; - SpringMVC & Hibernate : CannotCreateTransactionException: Could not open Hibernate Session for transaction; 无法为事务打开Hibernate会话:从类加载器中看不到ConnectionWrapper - Could not open Hibernate Session for transaction: ConnectionWrapper is not visible from class loader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM