PDA

View Full Version : BeanNameAutoProxyCreator Issue



rjmoran68
Jul 1st, 2005, 09:46 AM
I am having trouble getting the BeanNameAutoProxyCreator to work. When I configure a simple intreceptor with the ProxyBeanFactory it works fine, but when I attempt to do the same thing with the BeanNameAutoProxyCreator my bean is never proxied and the advice is never applied. I am not sure what I am doing wrong. Here is a portion of my configuration.

<beans>
<bean id="FullBookService" class="com.fmr.fiis.ws.fullbook.facade.CWsIPFullBookFacad eImpl"/>

<bean id="performanceThreshholdInterceptor" class="com.fmr.fiis.ws.fullbook.aop.CWsPerformanceInterce ptor">
<constructor-arg>
<value>3000</value>
</constructor-arg>
</bean>

<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNa meAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>performanceThreshholdInterceptor</value>
</list>
</property>
<property name="beanNames">
<list>
<value>FullBookService</value>
</list>
</property>

</bean>

rjmoran68
Jul 1st, 2005, 10:42 AM
I failed to call the refresh() method when creating the application context and loading the bean definitions. Apparently this is necessary for auto proxy functions.

hucmuc
Jul 1st, 2005, 11:13 AM
I failed to call the refresh() method when creating the application context and loading the bean definitions. Apparently this is necessary for auto proxy functions.

You shouldn't need to explicitly call refresh on the applicationContext (it is automatically called in the ApplicationContext constructor unless you specified false on one of the arguments).

Dino

rjmoran68
Jul 1st, 2005, 11:21 AM
I create the application context as follows:

GenericApplicationContext ac = new GenericApplicationContext();

//Create an XML Bean Definition Reader
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ac);

//Load The Bean Definitions
xmlReader.loadBeanDefinitions(new InputStreamResource(input));

//Refresh The Context
ac.refresh();

Perhaps I should a different constructor for the context. As is, it will not work unless I explicitly call refresh().

hucmuc
Jul 1st, 2005, 11:33 AM
Looking at the code in GenericApplicationContext, you're right; you need to call refresh since it won't do it automatically.

Why not use:

final BeanFactory beanFactory = new ClassPathXmlApplicationContext(appContextFile);

or
final BeanFactory beanFactory = new FileSystemXmlApplicationContext(appContextFile);

This will cut your lines of code to one line.

Dino

rjmoran68
Jul 1st, 2005, 11:37 AM
I will give that a try. Thanks for the help!