Java Aspect-Oriented Programming with Annotations

Let’s imagine you want to log the time taken by some annoted methods using a @LogExecTime annotation. I first create an annotation LogExecTime: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface LogExecTime { } Then I define an aspect: @Component // For Spring AOP @Aspect public class LogTimeAspect { @Around(value = “@annotation(annotation)”) public Object LogExecutionTime(final ProceedingJoinPoint joinPoint, final LogExecTime … Read more

Cross cutting concern example

Before understanding the Crosscutting Concern, we have to understand the Concern. A Concern is a term that refers to a part of the system divided on the basis of the functionality. There are two types of concerns: The concerns representing single and specific functionality for primary requirements are known as core concerns. OR Primary functionality … Read more

Aspect Oriented Programming vs. Object-Oriented Programming

Why “vs”? It is not “vs”. You can use Aspect Oriented programming in combination with functional programming, but also in combination with Object Oriented one. It is not “vs”, it is “Aspect Oriented Programming with Object Oriented Programming”. To me AOP is some kind of “meta-programming”. Everything that AOP does could also be done without … Read more

NOT using repository pattern, use the ORM as is (EF)

I’ve gone down many paths and created many implementations of repositories on different projects and… I’ve thrown the towel in and given up on it, here’s why. Coding for the exception Do you code for the 1% chance your database is going to change from one technology to another? If you’re thinking about your business’s … Read more

Use of proxies in Spring AOP

Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxies for your target objects. According to Spring documentation, in case your target implements at least one interface, a JDK dynamic proxy will be used. However if your target object does not implement any interfaces then a CGLIB proxy will be created. This … Read more

Javascript AOP libraries [closed]

Here is what I found until now : dotvoid’s implementation, clean syntax, nice to use, the article is a good introduction on why/how to use the given code, supports introductions, but is bugged, Dojo has what seems to be a good built-in implementation in dojox, here is a nice introduction on how to use it, … Read more

spring creates proxy for wrong classes when using aop class level annotation

Andy Brown is right, it is by design. The reason is that according to the AspectJ manual pointcut designators such as @args, @this, @target, @within, @withincode, and @annotation (or the subset of those available in Spring AOP) are used to match based on the presence of an annotation at runtime. This is why in the … Read more

Tracking down cause of Spring’s “not eligible for auto-proxying”

Follow this recipe: Open BeanPostProcessorChecker in your IDE (it’s an inner class of AbstractApplicationContext) Set a breakpoint on if (logger.isInfoEnabled()) { in the method postProcessAfterInitialization Run your code When you hit the breakpoint, look for calls to getBean(String,Class<T>) in your stack trace. One of these calls will try to create a BeanPostProcessor. That bean should … Read more

Logging, Aspect Oriented Programming, and Dependency Injection – Trying to make sense of it all

Logging is not a Service, it’s a cross-cutting concern. As such, it’s best implemented with a Decorator. However, adding lots of Decorators just to enable logging of various different services tend to violate DRY, in which case you can then further evolve those Decorators into a single Interceptor. While you can use IL weaving to … Read more