Spring AOP works without @EnableAspectJAutoProxy?

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

Is using Spring AOP for logging a good idea?

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

@AspectJ pointcut for all methods inside package

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

Using a request scoped bean outside of an actual web request

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

Spring AOP – why do i need aspectjweaver?

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

Spring autowired bean for @Aspect aspect is null

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

tech