AOP ProxyFactoryBean - Can I use this as much as I want?

56 views
Skip to first unread message

Jonathan Logue

unread,
Dec 28, 2007, 7:45:19 PM12/28/07
to ColdSpring-Users
I have been working on a fairly robust code generation tool for a
current project and I ran into an issue when setting up advisors. In
autowiring dependencies between various class managers I was using the
straight class path and I found that by using the target approach, the
type is no longer accurate and should actually be changed to
coldspring.aop.framework.ProxyFactoryBean... right?

So if this is true, my question is whether it is ok to just use the
ProxyFactoryBean class for all the business classes in my application,
or will that create performance penalties. I could modify my code
generation tools to check for implementation of the interceptor
pattern, but I would not do it if there is no penalty.

So, does this cost me?

<bean id="CompanyGateway" class="project.dao.CompanyGateway"
autowire="byName" />
<bean id="CompanyManagerTarget" class="project.service.CompanyManager"
autowire="byName" />
<bean id="CompanyManager"
class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="CompanyManagerTarget" />
</property>
</bean>

vs. this...

<bean id="CompanyGateway" class="project.dao.CompanyGateway"
autowire="byName" />
<bean id="CompanyManager" class="project.service.CompanyManager"
autowire="byName" />

Thanks.

Chris Scott

unread,
Dec 28, 2007, 8:27:07 PM12/28/07
to coldspri...@googlegroups.com
I proxy every single one of my manager / service classes in every application I write. I consider the small performance penalty to be highly outweighed by what I can then paint into my services with AOP

Jonathan Logue

unread,
Dec 28, 2007, 8:53:22 PM12/28/07
to ColdSpring-Users
Thanks Chris. I will go ahead and proceed with that approach unless I
hear compelling follow-up advice to do otherwise.

Much appreciated.


On Dec 28, 5:27 pm, "Chris Scott" <chris.scott....@gmail.com> wrote:
> I proxy every single one of my manager / service classes in every
> application I write. I consider the small performance penalty to be highly
> outweighed by what I can then paint into my services with AOP
>

Barney Boisvert

unread,
Dec 29, 2007, 12:59:53 PM12/29/07
to coldspri...@googlegroups.com
I'm with Chris.  AOP is totally worth the performance cost, including the initial load time when ColdSpring has to regenerate all the proxy classes.  One thing that I prefer is to configure my target bean as an unnamed inner bean, rather than being a top-level bean.  That way it's impossible to get the unproxied (target) bean by accident.  This:

<bean id="CompanyManagerTarget" class="project.service.CompanyManager"
autowire="byName" />
<bean id="CompanyManager"
class="coldspring.aop.framework
.ProxyFactoryBean">
       <property name="target">
               <ref bean="CompanyManagerTarget" />
       </property>
</bean>

becomes this instead:

<bean id="CompanyManager"
class="coldspring.aop.framework
.ProxyFactoryBean">
       <property name="target">

               <bean id="CompanyManagerTarget" class=" project.service.CompanyManager"
autowire="byName" />
       </property>
</bean>

In addition, that distinction is useful to tools (like SpringIDE) and happens to save a touch of typing.

cheers,
barneyb
--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/

Got Gmail? I have 100 invites.

Sean Corfield

unread,
Dec 29, 2007, 1:50:49 PM12/29/07
to coldspri...@googlegroups.com
On Dec 29, 2007 9:59 AM, Barney Boisvert <bboi...@gmail.com> wrote:
> becomes this instead:
>
> <bean id="CompanyManager"
> class="coldspring.aop.framework
> .ProxyFactoryBean">
> <property name="target">
> <bean id="CompanyManagerTarget" class="
> project.service.CompanyManager"
> autowire="byName" />
> </property>
> </bean>

That looks like the inner bean has a name. Did you mean:

<bean class="project.service.CompanyManager" />

Just curious since I've never worked with inner beans like this and I
don't use AOP much. After this thread, I might use it a lot more. I
hadn't thought of using it as a default even when I don't actually
have any advice to wire in...
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Jonathan Logue

unread,
Dec 29, 2007, 5:23:26 PM12/29/07
to ColdSpring-Users
It sure makes for a more consistent implementation to use it across
the board.

Barney, thanks for the recommendation - it is much cleaner on top of
the reasons you mentioned.

On Dec 29, 10:50 am, "Sean Corfield" <seancorfi...@gmail.com> wrote:
> On Dec 29, 2007 9:59 AM, Barney Boisvert <bboisv...@gmail.com> wrote:
>
> > becomes this instead:
>
> > <bean id="CompanyManager"
> > class="coldspring.aop.framework
> > .ProxyFactoryBean">
> > <property name="target">
> > <bean id="CompanyManagerTarget" class="
> > project.service.CompanyManager"
> > autowire="byName" />
> > </property>
> > </bean>
>
> That looks like the inner bean has a name. Did you mean:
>
> <bean class="project.service.CompanyManager" />
>
> Just curious since I've never worked with inner beans like this and I
> don't use AOP much. After this thread, I might use it a lot more. I
> hadn't thought of using it as a default even when I don't actually
> have any advice to wire in...
> --
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View --http://corfield.org/

Barney Boisvert

unread,
Dec 31, 2007, 1:23:34 AM12/31/07
to coldspri...@googlegroups.com
Yeah, I meant to remove the ID attribute, sorry about that.  I just copied and pasted the provided example into the right arrangement and forgot that part.

cheers,
barneyb

Tom Chiverton

unread,
Jan 9, 2008, 1:47:02 PM1/9/08
to coldspri...@googlegroups.com
> > <property name="target">
> > <bean id="CompanyManagerTarget" class="
> > project.service.CompanyManager"
> > autowire="byName" />
> > </property>

That's nice... but means the CompanyManagerTarget can't be reused
across other Proxies ?

--
Tom

Barney Boisvert

unread,
Jan 9, 2008, 1:50:58 PM1/9/08
to coldspri...@googlegroups.com
Correct, you can't proxy a single instance multiple times under
different aliases. What's the use case? I've never considered
multiple proxied versions of a single bean.

cheers,
barneyb

--

Tom Chiverton

unread,
Jan 9, 2008, 4:11:57 PM1/9/08
to coldspri...@googlegroups.com
On 09/01/2008, Barney Boisvert <bboi...@gmail.com> wrote:
> Correct, you can't proxy a single instance multiple times under
> different aliases. What's the use case? I've never considered
> multiple proxied versions of a single bean.

I just meant that- suppose I have a proxied EmailManager, but also
want to reuse that in a UserManger. I'd have to break out the
EmailManager from the 'internal' bean into a broper bean with an id.
So I'd be tempted to just use 'proper' beans all the time, as it's
less to change if dependencies alter.

--
Tom

Jon Messer

unread,
Jan 9, 2008, 4:17:56 PM1/9/08
to coldspri...@googlegroups.com
Not that I'm advocating it, but you could use the proxied EmailManager in UserManager, thus keeping all the AOP applied to it in place...

Personally I define a XXXServiceTarget that I can use for proxy and remote proxy or unit testing without the AOP.

Barney Boisvert

unread,
Jan 9, 2008, 4:32:47 PM1/9/08
to coldspri...@googlegroups.com
No, you'd use the proxied object for that. Here's the simple (no AOP) case:

<bean id="usermanager" class="usermanager">
<property name="emailmanager"><ref id="emailmanager" /></property>
</bean>

<bean id="emailmanager" class="emailmanager">
</bean>

With the AOP, it doesn't change except for the wrapping:

<bean id="usermanager">
<property name="emailmanager"><ref id="emailmanager" /></property>
</bean>

<bean id="emailmanager" class="ProxyFactoryBean">
<property name="target">
<bean class="emailmanager" />
</property>
</bean>

The fact that emailmanager is proxied is irrelevant to everyone,
usermanager just uses it as-is, wrapped or not.

cheers,
barneyb

--

Brian Kotek

unread,
Jan 9, 2008, 4:35:16 PM1/9/08
to coldspri...@googlegroups.com
As Barney says, this is the whole point of creating the proxy. To the rest of the system, the proxied version IS the target component.
Reply all
Reply to author
Forward
0 new messages