Expand|Select|Wrap|Line Numbers
- public class SpringAOP implements SpringAOPInterface
- {
- public void showMessage()
- {
- System.out.println("I m learning Spring+AOP, & i really enjoying dis :-)");
- }
- }
- public interface SpringAOPInterface
- {
- public void showMessage();
- }
- import org.springframework.aop.*;
- import java.lang.reflect.Method;
- public class SpringAOPAdvice implements MethodBeforeAdvice
- {
- public void before(Method method,Object args[],Object Target) throws Throwable
- {
- System.out.println("My logging message is here");
- }
- }
- import org.springframework.beans.factory.*;
- import org.springframework.beans.factory.xml.*;
- import org.springframework.context.support.*;
- import org.springframework.core.io.*;
- public class SpringAOPTest
- {
- public static void main(String args[])
- {
- /*BeanFactory b = new XmlBeanFactory(new FileSystemResource("c:/SpringAOP.xml"));
- ((SpringAOP)b.getBean("testTarget")).showMessage();*/
- FileSystemXmlApplicationContext c = new FileSystemXmlApplicationContext("c:/SpringAOP.xml");
- ((SpringAOP)c.getBean("testTarget")).showMessage();
- System.out.println("Yahoo....Done it............!!!");
- }
- }
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
- <bean id="testTarget" class="SpringAOP"/>
- <bean id="testAdvice" class="SpringAOPAdvice"/>
- <!--<bean id="testPointcutAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
- <property name="mappedName">
- <value>void showMessage()</value>
- </property>
- <property name="advice">
- <ref bean="testAdvice"/>
- </property>
- </bean>-->
- <bean id="testProxyBean" class="org.springframework.aop.framework.ProxyFactoryBean">
- <property name="interceptorNames">
- <list>
- <value>testAdvice</value>
- </list>
- </property>
- <property name="target">
- <ref bean="testTarget"/>
- </property>
- </bean>
- </beans>
Where I am going wrong.
Please help !
Kind regards,
Dmjpro.