java - Spring AOP. Getting the bean name from the JoinPoint - Stack Overflow
Stream.of(joinPoint.getTarget().getClass().getAnnotationsByType(Service.class)) .forEach(q -> logger.info(q.value()));
to get the bean as declared by @Service
annotation.
However, not all beans are created this way. Some are created by @Bean
annotated methods, some can even be added manually to the the context. So, if you annotate your bean classes with @Component
, @Service
, @Qualifier
etc. and use @ComponentScan
you might get what you want. You just need to remember that it's not the universal way to retrieve all beans currently available in the context (it will not work for classes without any annotations/metadata).
Read full article from java - Spring AOP. Getting the bean name from the JoinPoint - Stack Overflow
No comments:
Post a Comment