Advertisement
Guest User

Spring AOP PointCut Not working

a guest
Jan 3rd, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. ************MyAspect.java*************
  2. package com.mkyong.aspect;
  3.  
  4. import org.aspectj.lang.ProceedingJoinPoint;
  5. import org.aspectj.lang.annotation.Aspect;
  6. import org.aspectj.lang.annotation.Before;
  7. import org.aspectj.lang.annotation.Pointcut;
  8.  
  9. @Aspect
  10. public class MyAspect {
  11.  
  12.     @Before("checkMyDetails()")
  13.     public void myLogging() throws Throwable {
  14.         System.out.println("Logger added successfully");
  15.  
  16.     }
  17.    
  18.     @Pointcut("within(com.mkyong.customer.bo.*)")
  19.     public void checkMyDetails() {}
  20.  
  21. }
  22.  
  23. **********************************************************
  24. MyTest.java
  25.  
  26. package com.mkyong.customer.bo;
  27.  
  28. public interface MyTest {
  29.     void addMe(String s);
  30. }
  31. *******************************************************
  32. MyTestImpl.java
  33.  
  34. package com.mkyong.customer.bo.impl;
  35.  
  36. import com.mkyong.customer.bo.MyTest;
  37.  
  38. public class MyTestImpl implements MyTest {
  39.  
  40.     public void addMe(String s) {
  41.         System.out.println("I had added the " + s + "  person");
  42.  
  43.     }
  44.  
  45. }
  46.  
  47. *********************************************************************************
  48. Spring-Customer.xml
  49.  
  50. <beans xmlns="http://www.springframework.org/schema/beans"
  51.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  52.     xmlns:aop="http://www.springframework.org/schema/aop"
  53.     xsi:schemaLocation="http://www.springframework.org/schema/beans
  54.     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  55.     http://www.springframework.org/schema/aop
  56.     http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
  57.  
  58.     <aop:aspectj-autoproxy />
  59.  
  60.     <bean id="customerBo" class="com.mkyong.customer.bo.impl.CustomerBoImpl" />
  61.  
  62.     <!-- Aspect -->
  63.     <bean id="logAspect" class="com.mkyong.aspect.LoggingAspect" />
  64.  
  65. </beans>
  66.  
  67. ***************************************************************************************
  68.  
  69. App.java
  70.  
  71. package com.mkyong.core;
  72.  
  73. import org.springframework.context.ApplicationContext;
  74. import org.springframework.context.support.ClassPathXmlApplicationContext;
  75.  
  76. import com.mkyong.customer.bo.MyTest;
  77.  
  78. public class App {
  79.     public static void main(String[] args) throws Exception {
  80.  
  81.         ApplicationContext appContext = new ClassPathXmlApplicationContext("common-files.xml");
  82.  
  83.         MyTest testing = (MyTest) appContext.getBean("testBo");
  84.  
  85.         testing.addMe("Srinu");
  86.  
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement