Is there a way I can configure Spring AOP to allow printing of entry and exit of methods for multiple classes without defining individual proxies for each one?
Is there a way I can configure Spring AOP to allow printing of entry and exit of methods for multiple classes without defining individual proxies for each one?
Randy
Yes. You can use BeanNameAutoProxyCreator to apply the Trace Advisor. BeanNameAutoProxyCreator can proxy singletons as well as prototypes.
HTH
Or another "auto proxy creator" like DefaultAdvisorAutoProxyCreator. This looks at all Advisors defined in your context, and checks whether the pointcut matches each bean defined.
I'm trying to use the DefaultAdvisorAutoProxyCreator as such:
TraceBeforeAdvice is the same as the Spring TraceInterceptor, but logs input arguments as well. When I add these beans, I get the following exception first thing:Code:<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> <bean id="tracingBeforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="pattern"><value>.*</value></property> <property name="advice"><bean class="com.test.service.audit.TraceBeforeAdvice"/></property> </bean>
I can provide a longer stack trace if that would help. The AppConfig bean is the first one created and being injected. I'm using 1.2RC2. My property takes the interface (com.test.data.AppConfig). I took what I found in the reference docs and Pro Spring, but probably made a mistaken assumption in filling in the blanks. Are there any examples of application-wide (all classes/all methods) tracing using AOP in any of the projects or sub-projects? I checked the samples and didn't see anything.Code:org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy40] to required type [com.test.data.jdbc.AppConfigJdbcImpl] for property 'appConfig' at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:1010) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:772)
The app works fine without it.
Thanks in advance.
Randy
did you find a solution for your problem? Please let me know. Iam interested.
Are you using com.xxx.AppConfigJdbcImpl as the parameter type for the setAppConfig() method? You should instead have an interface, namely AppConfig and then have AppConfigJdbcImpl implement this interface. It looks like a JDK-proxy (which implements interfaces) and you are asking for a specific implementation.
Jess
I am wondering if adding cglib would solve this?
Did anyone find out what the cause of this is?
I am trying to do the same thing, using BeanNameAutoProxyCreator, and getting the same error. The proxy creator is applying enter/exit tracing to methods, and also logging exceptions to a particular log.
Code:
The full stack trace looks like this:Code:<bean id="proxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>*</value> </list> </property> <property name="interceptorNames"> <list> <value>loggingThrowsAdvice</value> <value>tracingBeforeAdvice</value> <value>tracingAfterAdvice</value> </list> </property> </bean> <!-- Advice --> <bean id="loggingThrowsAdvice" class="com.nike.gtcustoms.business.LoggingThrowsAdvice"/> <bean id="tracingBeforeAdvice" class="com.nike.gtcustoms.business.TracingBeforeAdvice"/> <bean id="tracingAfterAdvice" class="com.nike.gtcustoms.business.TracingAfterAdvice"/>
Without the aspects, the application runs fine.Code:2006-03-06 10:42:07,739 ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one handler method must be found in class [class $Proxy0] java.lang.IllegalArgumentException: At least one handler method must be found in class [class $Proxy0] at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.<init>(ThrowsAdviceInterceptor.java:86) at org.springframework.aop.framework.adapter.ThrowsAdviceAdapter.getInterceptor(ThrowsAdviceAdapter.java:41) at org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry.getInterceptors(DefaultAdvisorAdapterRegistry.java:77) at org.springframework.aop.framework.AdvisorChainFactoryUtils.calculateInterceptorsAndDynamicInterceptionAdvice(AdvisorChainFactoryUtils.java:77) at org.springframework.aop.framework.HashMapCachingAdvisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(HashMapCachingAdvisorChainFactory.java:47) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:156) at $Proxy2.getConnection(Unknown Source) at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:885) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:797) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:860) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:829) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:409) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:238) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:148) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:247) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:240) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:178) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3692) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4127) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:804) at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:693) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020) at org.apache.catalina.core.StandardHost.start(StandardHost.java:718) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442) at org.apache.catalina.core.StandardService.start(StandardService.java:450) at org.apache.catalina.core.StandardServer.start(StandardServer.java:680) at org.apache.catalina.startup.Catalina.start(Catalina.java:536) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Since I am applying these aspects to all beans (including beans that are already being proxied), is it possible that I'm proxying proxied objects, which is creating this error?
So,
I tried running the app with one advice at a time. The stack trace in my previous post is when I only have the ThrowsAdvice advice enabled.
The following stack trace occurs when I only have the TracingBeforeAdvice enabled (it is similar to the stack trace in a previous posting in this thread).
Code:2006-03-06 14:33:13,328 ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LiquidationDAO' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy7] to required type [org.springframework.orm.hibernate3.HibernateTemplate] for property 'hibernateTemplate'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found] PropertyAccessExceptionsException (1 errors) org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy7] to required type [org.springframework.orm.hibernate3.HibernateTemplate] for property 'hibernateTemplate'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found java.lang.IllegalArgumentException: No matching editors or conversion strategy found at org.springframework.beans.PropertyTypeConverter.doTypeConversionIfNecessary(PropertyTypeConverter.java:156) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:723) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:575) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:769) at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:796) at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:785) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:775) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:575) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:405) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:238) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:148) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:253) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:240) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:178) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3692) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4127) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:804) at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:693) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020) at org.apache.catalina.core.StandardHost.start(StandardHost.java:718) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442) at org.apache.catalina.core.StandardService.start(StandardService.java:450) at org.apache.catalina.core.StandardServer.start(StandardServer.java:680) at org.apache.catalina.startup.Catalina.start(Catalina.java:536) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Try changing the order of interceptors from
<list>
<value>loggingThrowsAdvice</value>
<value>tracingBeforeAdvice</value>
<value>tracingAfterAdvice</value>
</list>
to ..........
<list>
<value>tracingBeforeAdvice</value>
<value>loggingThrowsAdvice</value>
<value>tracingAfterAdvice</value>
</list>