You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hibernate session cannot be found after upgrading Tomcat from 7.0.50 to 8.0.3 [SPR-11447] #16073
This is working as expected until Tomcat 7.0.50. But when I deploy on 8.0.3 the first attempt to access the database, i.e. when I am trying to login to the application, fails:
19-Feb-2014 16:27:24.083 SEVERE [http-nio-8084-exec-12] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [default] in context with path [/test] threw exception
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:992)
After removing mode="aspectj" from <tx:annotation-driven/> the above mentioned login works and so the session was obviously found then (but code marked with @Transactional fails now).
This is probably due to load-time weaving generally not working, as in #16072. Try removing any spring-instrument jars, use a recent Spring version, and let context:load-time-weaver/ autodetect Tomcat's new built-in instrumentation capabilities. This should work out of the box now, without any special Tomcat setup. Unfortunately, old Spring Tomcat extensions can get in the way here :-(
Copy spring-instrument-tomcat-3.2.8.RELEASE.jar to Tomcat's lib folder and specify org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader in my webapp's META-INF/context.xml
Do none of the two points above
The result is that my webapp only works (completely) for the second test case above and so I evaluated the other two test cases a bit more:
Checking the (same-looking) logs for those two test cases, it seems that the javaagent specification is simply ignored and Tomcat's own instrumentable (since 8.0.x) WebappClassLoader is used in both cases (see also #16072):
INFO [org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver] - The ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide a 'getThrowawayClassLoader()' method; SimpleThrowawayClassLoader will be used instead.
INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Using a reflective load-time weaver for class loader: org.apache.catalina.loader.WebappClassLoader
INFO [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoader.addTransformer Added class file transformer [org.springframework.context.weaving.AspectJWeavingEnabler$AspectJClassBypassingClassFileTransformer@6c86b58b] to web application [/test].
So in my initial report, I mention that after removing mode="aspectj" from <tx:annotation-driven/> I am able to login but I forgot to explicitly mention that all regular annotated Spring beans (e.g. @Component @Scope("session")) were actually found.
Therefore I testing now to...
re-add <tx:annotation-driven mode="aspectj"/> to the application context
remove the mentioned database access marked with @Transactional and triggered by an ApplicationListener<ApplicationEvent>/AuthenticationSuccessEvent
add the following test bean
@Component
@Scope("session")
public class TestBean {
public String getHelloWorld() {
return "Hello World!!!";
}
}
call this method from the welcome page with #{testBean.helloWorld}
The result is successful in that I could log in and the welcome page showed the message from #{testBean.helloWorld}. Therefore the load time weaving employing Tomcat's own instrumentable WebappClassLoader seems to work in general.
BUT as soon as I now call any database method marked as @Transactional then I get the exception No Session found for current thread.
Activity
spring-projects-issues commentedon Feb 19, 2014
Juergen Hoeller commented
This is probably due to load-time weaving generally not working, as in #16072. Try removing any spring-instrument jars, use a recent Spring version, and let context:load-time-weaver/ autodetect Tomcat's new built-in instrumentation capabilities. This should work out of the box now, without any special Tomcat setup. Unfortunately, old Spring Tomcat extensions can get in the way here :-(
Juergen
spring-projects-issues commentedon Feb 19, 2014
Holger Stenzhorn commented
I have performed some additional testing on Tomcat 8.0.3 (also in relation to issue #16072) using three test cases:
-javaagent:/some/path/to/spring-instrument-3.2.8.RELEASE.jar"spring-instrument-tomcat-3.2.8.RELEASE.jarto Tomcat's lib folder and specifyorg.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoaderin my webapp'sMETA-INF/context.xmlThe result is that my webapp only works (completely) for the second test case above and so I evaluated the other two test cases a bit more:
Checking the (same-looking) logs for those two test cases, it seems that the
javaagentspecification is simply ignored and Tomcat's own instrumentable (since 8.0.x)WebappClassLoaderis used in both cases (see also #16072):So in my initial report, I mention that after removing
mode="aspectj"from<tx:annotation-driven/>I am able to login but I forgot to explicitly mention that all regular annotated Spring beans (e.g.@Component @Scope("session")) were actually found.Therefore I testing now to...
<tx:annotation-driven mode="aspectj"/>to the application context@Transactionaland triggered by anApplicationListener<ApplicationEvent>/AuthenticationSuccessEvent#{testBean.helloWorld}The result is successful in that I could log in and the welcome page showed the message from
#{testBean.helloWorld}. Therefore the load time weaving employing Tomcat's own instrumentableWebappClassLoaderseems to work in general.BUT as soon as I now call any database method marked as
@Transactionalthen I get the exceptionNo Session found for current thread.spring-projects-issues commentedon Dec 24, 2015
Pratheesh TU commented
Same issue is happening with us, which is blocking us to deploy our application to Tomcat 8.0. Please resolve this issue!!
spring-projects-issues commentedon Jan 12, 2019
Bulk closing outdated, unresolved issues. Please, reopen if still relevant.