Spring Hibernate - failed to get session with transaction synchronization for current thread
Why am I posting this?
After hours of searching / analyzing / getting paranoid, I would like to share my guilt with you - I nailed my cause of the problem.
When did it happen?
- on app server (in my case embedded tomcat) - tests had no problem
- on two specific @Services on which the methods have been properly annotated with @Transactional
What is the problem?
- Missing @EnableTransactionManagement in @Configuration
- Some Grid-related AEP issues such as not having a default constructor in a service that does not implement the interface (AFAIK this issue no longer exists since Spring 4.0)
What was the problem?
I use CustomPermisionEvaluator for Security for example to protect methods like this:
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
@PreAuthorize("hasPermission(null, 'SERVICE.ASSOCIATION.FIND_BY_NAME')")
public ResponseEntity<AssociationResult> findByName(@PathVariable String name) {
//do stuff
}
To do this, I need to extend the GlobalMethodSecurityConfiguration function to access your CustomPermissionEvaluator. There I used @Autowiring to get access to the beans needed to evaluate the permission. And guess it was those 2 @Services that the TransactionInterceptor ignored.
TL; DR
Don't allow autwire beans in GlobalMethodSecurityConfiguration => after that they won't be intercepted correctly.
+3
source to share
No one has answered this question yet