SEC-2136: Injecting Bean in a class used in custom PermissionEvaluator leads to NoSuchBeanDefinitionException #2362
Autowiring a bean in a class used in a custom PermissionEvaluator leads to NoSuchBeanDefinitionException. If the @autowire annotation is commented in code, the context loads correctly (but tests obviously then fail).
This is similar to referenced post in spring forums.
Attached is a sample App (maven) with the according test case.
Rob Winch said:
After some feedback from olivergierke there seems to be little that Spring Data can do to prevent the issue. Specifically, Spring Data cannot make the EntityManager lazy because it needs to use it to validate the queries annotated. There are some things we can do on the Spring Security side to help prevent issues like this which have been integrated into master. Please see commit 914ec45
In the meantime, to work around this issue, you can proxy your permissionEvaluator using LazyInitTargetSource as shown below: