Could you share a copy of your pom.xml? I tried running your code with the same setup, including @EnableCaching
and spring-boot-starter-cache
, and it worked as expected. Here’s the output I see:
Services annotated with @DataService:
Bean Name: barService, Class: BarService
Bean Name: fooService, Class: FooService
One thing you might want to try is using AopProxyUtils.ultimateTargetClass(bean)
in your AnnotationProcessor
.
This approach helps because AopProxyUtils.ultimateTargetClass(bean)
retrieves the original class behind any proxies that Spring might create when caching is enabled.
When you use this method, you’ll get the actual class name, which ensures that any annotations on the original class are accessible, even when proxies are involved.
Here’s an example of how you might update the code:
IService bean = (IService) entry.getValue();
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean);
System.out.println("Bean Name: " + beanName + ", Class: " + targetClass.getSimpleName());
Using targetClass
like this should prevent NullPointerException
issues caused by accessing annotations on a proxy class. Let me know if this helps!