Arugal commented on issue #3035: NPE Aspect
URL: https://github.com/apache/skywalking/issues/3035#issuecomment-510758154
 
 
   ```
   spring-boot-starter-aop:2.1.1.RELEAS
   ```
   ```
   @SpringBootApplication
   public class AopApplication implements CommandLineRunner {
   
       public static void main(String[] args) {
           SpringApplication.run(AopApplication.class);
       }
   
       @Autowired
       private Service service;
   
       @Override
       public void run(String... args) throws Exception {
           System.out.println("autowired:" + System.identityHashCode(service));
   
           Method method1 = Service.class.getDeclaredMethod("method1");
           method1.setAccessible(true);
           method1.invoke(service);
   
           Method method2 = Service.class.getDeclaredMethod("method2");
           method2.setAccessible(true);
           method2.invoke(service);
       }
   }
   @Aspect
   @Component
   public class AopAspect {
   
       @Pointcut("execution(* com.github.sunnus3.example.spring.Service.*(..))")
       public void aop() {
   
       }
   
       @Before("aop()")
       public void before(JoinPoint joinPoint) {
           System.out.println("before ...");
       }
   }
   @Component
   public class Service {
   
   
       private void method1() {
           System.out.println("private method: " + 
System.identityHashCode(this));
       }
   
       public void method2() {
           System.out.println("public  method: " + 
System.identityHashCode(this));
       }
   }
   
   Result
   autowired:680988889
   private method: 680988889
   before ...
   public  method: 1792227359
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to