问题
Why am I posting this?
After several hours of search / analysis / getting paranoid I would like to share my fault with you - I nailed down my cause of the problem.
When did it happen?
- within the application server (in my case embedded tomcat) - tests had no problem
- on two specific @Services on which the methods got properly annotated with @Transactional
What was not the problem?
- Missing @EnableTransactionManagement in the @Configuration
- Some weired AOP issue, eg having no default constructor in a Service not implementing an interface (AFAIK this problem does not exist anymore since Spring 4.0)
What was the problem?
I am using a CustomPermisionEvaluator for Security eg for securing 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
}
For doing this I have to extend the GlobalMethodSecurityConfiguration to get my CustomPermissionEvaluator into business. In there I used @Autowiring to get access to the beans needed for the permission evaluation. And guess what - this were those 2 @Services which the TransactionInterceptor ignored.
tl;dr
Do not autowire beans into GlobalMethodSecurityConfiguration => they will not get intercepted properly afterwards.
来源:https://stackoverflow.com/questions/31059372/spring-hibernate-could-not-obtain-transaction-synchronized-session-for-current