jmix
jmix copied to clipboard
Spring AOP and view controller
General description of the problem:
At the moment, if we want to use a simple boxed approach to writing aspects, then we will face the problem that writing aspects that will belong to the view controller class is impossible.
Since when creating a proxy object, it will not have an @ViewController
annotation and the screen will not open.
This occurs because the @ViewController
annotation is not annotated with the @Inherited
annotation.
Technical details:
- First of all we need to create simple aspect like this:
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class ExampleAspect {
private static final Logger log = LoggerFactory.getLogger(ExampleAspect.class);
@Before(value = "execution(* com.company.demo.view.user.UserListView.onInit(..))")
public void onInitInLogView(JoinPoint joinPoint) {
log.info("onInit AOP");
}
}
- In the second step, we annotate any public method in the view controller with an com.company.example.ExampleAnnotation
- As a result, we will get a view creation error when we try to go to the view associated with controller.
Solution:
Add @Inherited
annotation to @ViewController
annotation.