Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ************MyAspect.java*************
- package com.mkyong.aspect;
- import org.aspectj.lang.ProceedingJoinPoint;
- import org.aspectj.lang.annotation.Aspect;
- import org.aspectj.lang.annotation.Before;
- import org.aspectj.lang.annotation.Pointcut;
- @Aspect
- public class MyAspect {
- @Before("checkMyDetails()")
- public void myLogging() throws Throwable {
- System.out.println("Logger added successfully");
- }
- @Pointcut("within(com.mkyong.customer.bo.*)")
- public void checkMyDetails() {}
- }
- **********************************************************
- MyTest.java
- package com.mkyong.customer.bo;
- public interface MyTest {
- void addMe(String s);
- }
- *******************************************************
- MyTestImpl.java
- package com.mkyong.customer.bo.impl;
- import com.mkyong.customer.bo.MyTest;
- public class MyTestImpl implements MyTest {
- public void addMe(String s) {
- System.out.println("I had added the " + s + " person");
- }
- }
- *********************************************************************************
- Spring-Customer.xml
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
- <aop:aspectj-autoproxy />
- <bean id="customerBo" class="com.mkyong.customer.bo.impl.CustomerBoImpl" />
- <!-- Aspect -->
- <bean id="logAspect" class="com.mkyong.aspect.LoggingAspect" />
- </beans>
- ***************************************************************************************
- App.java
- package com.mkyong.core;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.mkyong.customer.bo.MyTest;
- public class App {
- public static void main(String[] args) throws Exception {
- ApplicationContext appContext = new ClassPathXmlApplicationContext("common-files.xml");
- MyTest testing = (MyTest) appContext.getBean("testBo");
- testing.addMe("Srinu");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement