What the difference between these below...
@org.aspectj.lang.annotation.Aspect
public class Test {
//@Pointcut, @Around etc etc..
}
And
public aspect Test {
}
And what is the better to use for security among..
in spring app
Check here
Aspect declarations are supported by the org.aspectj.lang.annotation.Aspect annotation. The declaration:
@Aspect public class Foo {}
Is equivalent to:
public aspect Foo {}
NOTE: The first one is detected by spring. The later requires AspectJ.
And for the second question. The comparison is impossible. Because the first one is a framework and the later is a paradigm. Spring security uses AOP to secure method calls, AOP by itself is not a security mechanism. Unless of course, you are going to build your own security using AOP, which is re-inventing the wheel.
Marking your class Test
with @Aspect
annotation will make your class an Aspect, means Spring's ApplicationContext
or BeanFactory
will now read and scan your class to find advices
, pointcuts
, joinpoints
, you can define your extra cross-cutting functinality
(functionality which you keep separate from your business logic) which you want to get executed for some event like before a method call, after a method call, after method throw an exception etc.
AOP (Aspect-oriented programming)
is design pattern which spring follows to provide you cross-cutting functionality while Spring Security
is a part of complete spring framework, which you can use to secure your application
Spring Security internally uses AOP and Filters to do its work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With