Hi I'm trying to implement Pointcut but the Application context automatically destroies itself I have no idea why.
I have this MyInterceptor.java to set the Pointcut
Any my beans2.xml file:Code:@Aspect public class MyInterceptor { @Pointcut("execution (* spring.service.impl.PersonServiceBean.*(..))") private void anyMethod() {} @Before("anyMethod()") public void doAccessCheck() { System.out.println("before advice"); } }
Any my junit test file:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <aop:aspectj-autoproxy></aop:aspectj-autoproxy> <bean id="personService" class="spring.service.impl.PersonServiceBean"></bean> <bean id="myInterceptor" class="spring.service.MyInterceptor"></bean> </beans>
myPersonServiceBean has a save method which just prints a line just for testing.Code:public class SpringAOPTest { @BeforeClass public static void setUpBeforeClass() throws Exception { } @Test public void interceptorTest() { ApplicationContext cxt; cxt = new ClassPathXmlApplicationContext("beans2.xml"); PersonService personService = (PersonService)cxt.getBean("personService"); personService.save(); } }
the console output is:
usually it will just stop at Pre-instantiating..... but now it destroySingletons right after it is initiated. I have tested a little but since I'm new to this, I have completely no idea what went wrong. Can somebody help! Thank you in advaceCode:Apr 04, 2012 2:08:12 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@19422d2: display name [org.springframework.context.support.ClassPathXmlApplicationContext@19422d2]; startup date [Wed Apr 04 14:08:12 EDT 2012]; root of context hierarchy Apr 04, 2012 2:08:12 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [beans2.xml] Apr 04, 2012 2:08:13 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@19422d2]: org.springframework.beans.factory.support.DefaultListableBeanFactory@f6925f Apr 04, 2012 2:08:13 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f6925f: defining beans [org.springframework.aop.config.internalAutoProxyCreator,personService,myInterceptor]; root of factory hierarchy Apr 04, 2012 2:08:13 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f6925f: defining beans [org.springframework.aop.config.internalAutoProxyCreator,personService,myInterceptor]; root of factory hierarchy


Reply With Quote