ProxyFactoryBean, Autowiring, and non-initialized beans

197 views
Skip to first unread message

Steve Brownlee

unread,
Oct 17, 2008, 9:13:09 AM10/17/08
to ColdSpring-Users
I'll do my best to explain what I'm seeing, but it's somewhat
confusing if you're not using autowiring or the ProxyFactoryBean.

I've got three components, ComponentA ComponentB, and ComponentC.

Each component has one method named testMe(), and ComponentB has
accessors for ComponentA so that it can be autoWired in. Likewise for
ComponentC to access ComponentB
- ComponentA.testMe()
- ComponentB.testMe()
- ComponentB.setComponentA()
- ComponentB.getComponentA()
- ComponentC.testMe()
- ComponentC.setComponentB()
- ComponentC.getComponentB()

I proxy each component to use a basic exception logging advisor.
================================================
<bean id="ComponentA"
class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="path.to.ComponentA">
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>

<bean id="ComponentB"
class="coldspring.aop.framework.ProxyFactoryBean" autowire="byName">
<property name="target">
<bean class="path.to.ComponentB">
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>

<bean id="ComponentC"
class="coldspring.aop.framework.ProxyFactoryBean" autowire="byName">
<property name="target">
<bean class="path.to.ComponentC">
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>
================================================

Here's the confusing part, so hopefully I explain it clearly.

I instantiate a ComponentC bean, and inside the testMe() function, try
to access the autowired ComponentA from ComponentB.
================================================
<component name="ComponentC">

<cffunction name="testMe">
<cfset var imJustABill = variables.ComponentB.getComponentA() />
</cffunction>

</component>
================================================

ComponentA is autowired into ComponentB which is autowired into
ComponentC.

When I dump imJustABill, I get a
coldspring.aop.framework.ProxyFactoryBean object with only its
methods. ComponentA's method do not exist, so I of course get an
error if I attempt to execute the testMe() method of ComponentA.
================================================
<component name="ComponentC">

<cffunction name="testMe">
<cfset var imJustABill = variables.ComponentB.getComponentA() />
<cfset imJustABill.testMe() />
</cffunction>

</component>
================================================

Now this only happens when I use proxied beans. If I remove the
ProxyFactoryBean definition and make the beans point directly to the
source component, this error does not occur.

Hopefully a) this makes sense to someone, and b) someone knows a
workaround, or if it's a known bug.

Thanks all

- Steve

Don (SigmaProjects)

unread,
Oct 17, 2008, 9:26:45 AM10/17/08
to ColdSpring-Users
Just a shot in the dark here, but instead of...

<bean id="ComponentB"
class="coldspring.aop.framework.ProxyFactoryBean" autowire="byName">
<property name="target">
<bean class="path.to.ComponentB">
</property>
....
</bean>

Try

<bean id="ComponentB"
class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="path.to.ComponentB" autowire="byName">
</property>
....
</bean>

Move the autoWire attribute to the actual target bean, again im not
certain but it might help?

Tom Chiverton

unread,
Oct 17, 2008, 9:49:35 AM10/17/08
to coldspri...@googlegroups.com
You could also try using <ref bean="..... rather than anonymous inner beans.
--
Tom

Brian Kotek

unread,
Oct 17, 2008, 9:50:24 AM10/17/08
to coldspri...@googlegroups.com
Also what does your Advisor look like? Have you defined the mapped names?

Steve Brownlee

unread,
Oct 17, 2008, 9:57:06 AM10/17/08
to ColdSpring-Users
I've tried that to no avail :(

Steve Brownlee

unread,
Oct 17, 2008, 9:59:37 AM10/17/08
to ColdSpring-Users
For the time being, I'm capturing everything.....

<bean id="exceptionLoggingAdvisor"
class="coldspring.aop.support.NamedMethodPointcutAdvisor">
<property name="advice">
<bean id="exceptionLoggingAdvice"
class="utility.aop.advice.exception.LoggingThrowsAdvice">
<property name="loggingService">
<ref bean="loggingService" />
</property>
</bean>
</property>
<property name="mappedNames">
<value>*</value>
</property>
</bean>

On Oct 17, 8:50 am, "Brian Kotek" <brian...@gmail.com> wrote:
> Also what does your Advisor look like? Have you defined the mapped names?
>

Bill Rawlinson

unread,
Oct 17, 2008, 9:51:21 AM10/17/08
to coldspri...@googlegroups.com
I'm pretty sure the autowire has to be on the bean at the bean definition like he had initially.

I would define things like this:


<bean id="ComponentBTarget" class="path.to.componentB" autowire="true">
....
</bean>
<bean id="ComponentB" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="ComponentBTarget" />
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>

It is a bit more verbose but I have never had any problems approaching it like that.

Steve Brownlee

unread,
Oct 17, 2008, 11:39:05 AM10/17/08
to ColdSpring-Users
Well it doesn't have to be, in fact I've run into problems having it
on the target bean definition and NOT on the proxy definition. In any
case, I've tried switching the autowiring to the target bean in my
specific case and it makes no difference.

Brian Kotek

unread,
Oct 17, 2008, 1:25:55 PM10/17/08
to coldspri...@googlegroups.com
I've never had a problem passing proxied beans into other proxied beans, but I've always done it within the real bean, not in the proxy. In other words, I set the dependency in the original bean not the proxy that wraps it. I've never tried to do this with implicit autowiring though, I always declare bean properties explicitly.

Steve Brownlee

unread,
Oct 17, 2008, 3:04:00 PM10/17/08
to ColdSpring-Users
Yeah Brian, it looks like that's what is confusing ColdSpring. Once I
break it up into two definitions (per the example, into BaseComponentC
and ComponentC) and place the non-incidental dependencies as
contructor args, it works.

The combination of anonymous inner beans, autowiring and proxies was
just too much at once.

On Oct 17, 12:25 pm, "Brian Kotek" <brian...@gmail.com> wrote:
> I've never had a problem passing proxied beans into other proxied beans, but
> I've always done it within the real bean, not in the proxy. In other words,
> I set the dependency in the original bean not the proxy that wraps it. I've
> never tried to do this with implicit autowiring though, I always declare
> bean properties explicitly.
>
> On Fri, Oct 17, 2008 at 11:39 AM, Steve Brownlee
> <steven.brown...@gmail.com>wrote:

Brian Kotek

unread,
Oct 17, 2008, 4:03:46 PM10/17/08
to coldspri...@googlegroups.com
I still use anonymous inner beans, I just declare the properties within it.
Reply all
Reply to author
Forward
0 new messages