Obtain real Class object for Spring bean
Spring’s interface-based proxies implement TargetClassAware.
Spring’s interface-based proxies implement TargetClassAware.
This hack is extremely awkward, please consider refactoring your code or using AspectJ weaving. You may feel warned, here is the solution AopContext.currentProxy() JavaDoc. I blogged about it here and here.
Change the advice signature to @Around(value=”@annotation(sampleAnnotation)”) public Object display(ProceedingJoinPoint joinPoint, SampleAnnotation sampleAnnotation ) throws Throwable { // … } and you will have access to the value in the annotation. See docs for more info.
The @SpringBootApplication annotation contains the @EnableAutoConfiguration annotation. This autoconfiguration is one of the attractions of Spring Boot and makes configuration simpler. The auto configuration uses @Conditional type annotations (like @ConditionalOnClass and @ConditionalOnProperty) to scan the classpath and look for key classes that trigger the loading of ‘modules’ like AOP. Here is an example AopAutoConfiguration.java import … Read more
I used Spring AOP for implementing logging so I share my observations: Performance impact is not sufficient, it is less than impact of logging itself Having aspects configured in Spring configuration, you are able to completely disable logging code if necessary Debugging becomes more problematic as stack traces become rather longer Such decision sufficiently affects … Read more
How about one of these alternatives? A) General execution pointcut with package restrictions: execution(* *(..)) && ( within(com.abc.xyz..controller..*) || within(com.abc.xyz..service..*) || within(com.abc.xyz..dao..*) ) B) Package-restricted execution pointcuts: execution(* com.abc.xyz..controller..*(..)) || execution(* com.abc.xyz..service..*(..)) || execution(* com.abc.xyz..dao..*(..)) I prefer B, by the way, just because it is a bit shorter and easier to read. As you have … Read more
For Spring 4 Frameworks add servletContext.addListener(new RequestContextListener()); public class WebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class[] { RootConfiguration.class }; } @Override protected Class<?>[] getServletConfigClasses() { return new Class[] { WebMvcConfiguration.class }; } @Override protected String[] getServletMappings() { return new String[] { “/” }; } @Override protected Filter[] getServletFilters() { return … Read more
You need to enable load-time weaving (or other kinds of weaving) in order to use @Configurable. Make sure you enabled it correctly, as described in 7.8.4 Load-time weaving with AspectJ in the Spring Framework.
Spring AOP implementation I think is reusing some classes from the aspectj-weaver. It still uses dynamic proxies – doesn’t do byte code modification. The following comment from the spring forum might clarify. Spring isn’t using the AspectJ weaver in this case. It is simply reusing some of the classes from aspectjweaver.jar. -Ramnivas
The aspect is a singleton object and is created outside the Spring container. A solution with XML configuration is to use Spring’s factory method to retrieve the aspect. <bean id=”syncLoggingAspect” class=”uk.co.demo.SyncLoggingAspect” factory-method=”aspectOf” /> With this configuration the aspect will be treated as any other Spring bean and the autowiring will work as normal. You have … Read more