2. How to enable annotation-driven aspects in Spring?
Add <aop:aspectj-autoproxy/>to
spring config file.
<aop:aspectj-autoproxy/> will create an AnnotationAwareAspectJAutoProxyCreator in the Spring context and will automatically proxy beans whose methods match the pointcuts defined with @Pointcut annotations in @Aspect-annotated beans.
3. How to specify that an advice is executed outside the transaction of the join point?
Specify the orders of the aspect and transaction. For aspect, annotation org.springframework.core.annotation.Order can
be used. For transaction, order can be specified in spring config file. A greater value represents a lower priority.
4. How to specify the which advice take precedence while two advices advise the same method?
Again, use org.springframework.core.annotation.Order and
give them different values.
5. Are spring managed beans all singleton?
Not necessarily.
Various bean scopes can be specified with org.springframework.context.annotation.Scope.
singleton
Scopes a single bean definition to a single object instance per Spring IoC container.
prototype
Scopes a single bean definition to any number of object instances.
request
Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request
will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
session
Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring
ApplicationContext.
global session
Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware
Spring ApplicationContext.
For instance, annotate a class with @Scope("prototype"),
and each time bean of this type fetched is a new instance.