Home > Back-end >  How does the double-dot ".." syntax work in AspectJ?
How does the double-dot ".." syntax work in AspectJ?

Time:10-29

i need to put this aop aspect to work, but i always get error 404, i need to know if this dots, after controller is right. idk how these dots works, to acess the controller.

if can explain how the dots works.

<aop:aspect ref="permissionInterceptor">
  <aop:around
    method="invoke"
    pointcut="execution(* com.teste1.teste2.web.controller..*())
      and @annotation(com.teste1.ae.client.security.Permission)"
  />
</aop:aspect>

Is this correct?

CodePudding user response:

execution(* com.teste1.teste2.web.controller..*())

would mean - the execution of any method defined in the com.teste1.teste2.web.controller package or one of its sub-packages

.. is a special wild card which means any number of arguments will match. In the context of an execution pointcut it would be the current package or any sub-package of it.

Spring documentation reference : Examples

whereas (..) matches any number (zero or more) of parameters.

The expression with .. would work. You could verify if the controller methods gets advised when the and @annotation(com.teste1.ae.client.security.Permission) part is removed from the expression. If still the request results in 404 , please share the an MCVE or Aspect code to understand the logic further.

CodePudding user response:

Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects. (Such concerns are often termed crosscutting concerns in AOP literature.)

The pointcuts defined in such an aspect can be referred to anywhere that you need a pointcut expression. For example, to make the service layer transactional, you could write:

<aop:config>
<aop:advisor 
      pointcut="com.xyz.someapp.SystemArchitecture.businessService()"
      advice-ref="tx-advice"/>
</aop:config>

<tx:advice id="tx-advice">
  <tx:attributes>
    <tx:method name="*" propagation="REQUIRED"/>
  </tx:attributes>
</tx:advice>

We can declare an aspect in such way:

<aop:config>
  <aop:pointcut id="businessService" 
        expression="execution(* com.xyz.myapp.service.*.*(..))"/>   
</aop:config>
  • Related