AOP and factory-method

13 views
Skip to first unread message

daniel.d...@gmail.com

unread,
Dec 30, 2011, 10:00:45 AM12/30/11
to ColdSpring-Users
I am trying to add AOP advice to a bean that is generated by a custom
factory /snip/ <bean id="somethingfactory" class="somethingfactory"/>
<bean id="something" factory-bean="somethingfactory" factory-
method="makesomething" class='something'/> /snip/
It appears when I apply advice via the <AOP> schema to the class that
it does a strait create on the something object with out using the
factory.

If I use the older style ProxyFactoryBean it works just fine.

I would much perfer to use the pointcut style so that I do not have
declare exactly where advice should be used on each bean. Have tried
to walk though the coldspring getBean paths for the two styles and not
finding where the problem is. I have encluded simple examples below
of that is being used to test this issue.


<cfcomponent name="somethingfactory.cfc>

<cffunction name="init">
<cfreturn this>
</cffunction>

<cffunction name="makesomething">
<cfset var local=structnew()>

<cfset local.something= createObject( 'component', 'something')/>
<cfset local.something.setfoo(5)>
<cfset local.something.xxx=4>
<cfreturn local.something>
</cffunction>
</cfcomponent>


<cfcomponent name="something">

<cffunction name="init">

<cfreturn this>

</cffunction>

<cffunction name="setfoo">
<cfargument name="thevalue">
<cfset this.foo = arguments.thevalue>
</cffunction>
<cffunction name="getfoo">
<cfreturn this.foo>
</cffunction>

</cfcomponent>


<cfcomponent name="AOPtest"
implements="coldspring.aop.MethodInterceptor">

<cffunction name="init">
<cfreturn this>
</cffunction>


<cffunction name="invokeMethod" access="public" returntype="any"
output="FALSE">
<cfargument name="methodInvocation"
type="coldspring.aop.MethodInvocation" required="true" />
<cfset rtn = arguments.methodInvocation.proceed() />
</cffunction>
</cfcomponent>



<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
xmlns="http://www.coldspringframework.org/schema/beans"
xmlns:aop="http://www.coldspringframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.coldspringframework.org/
schema/beans http://coldspringframework.org/schema/coldspring-beans-2.0.xsd
http://www.coldspringframework.org/schema/aop
http://www.coldspringframework.org/schema/coldspring-aop-2.0.xsd"
>



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


<bean id="somethingfactory" class="somethingfactory"/>
<bean id="something" factory-bean="somethingfactory" factory-
method="makesomething" class='something'/>
<!-- new style does not work. -->
<!-- <aop:config>-->
<!-- <aop:aspect ref="aoptest">-->
<!-- <aop:around method="invokeMethod" pointcut="execution(public *
something.getfoo(..))"/>-->
<!-- </aop:aspect> -->
<!-- </aop:config>-->

<!-- old style works -->
<bean id="securityAdvisor"
class="coldspring.aop.support.NamedMethodPointcutAdvisor">
<property name="advice">
<ref bean="aoptest" />
</property>
<property name="mappedNames">
<value>getfoo</value>
</property>
</bean>

<bean id="somethingtest"
class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="something" />
</property>
<property name="interceptorNames">
<list>
<value>securityAdvisor</value>
</list>
</property>
</bean>

</beans>

daniel.d...@gmail.com

unread,
Dec 30, 2011, 2:26:42 PM12/30/11
to ColdSpring-Users
Found the issue and a solution. Probably not the overall best
solution and definatly not the cause. Somewhere in the AOP creation
of the bean it the beandefinition.create method does not get the
create_factorybean mixin overwritten onto the create method in the
cfcbeandefintiion.cfc. So I put an cfif in the create testing for
factorymethod/bean and then make a call to create_factorybean()
method. Everything works fine after that change.

On Dec 30, 10:00 am, "daniel.daughe...@gmail.com"
>            http://www.coldspringframework.org/schema/aophttp://www.coldspringframework.org/schema/coldspring-aop-2.0.xsd"

Mark Mandel

unread,
Dec 30, 2011, 6:29:52 PM12/30/11
to coldspri...@googlegroups.com

Thanks for the post, sounds like a legitimate bug.

I'm just in the middle of preparing for NYE, and setting up new laptop,but will jump on this as soon as I have a chance.

Will keep you updated.

Mark

Sent from my mobile doohickey.

--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.

Mark Mandel

unread,
Jan 2, 2012, 1:16:23 AM1/2/12
to coldspri...@googlegroups.com
Daniel,

Managed to find some time to look at this.

Can you paste (or email direct if it's private) the original XML schema you were trying to implement.

I'm trying to work out if the issue is with where the post processors fire, or it could well be the fact that factory-bean generated elements can't be matched against their classes, as they are not know.

I'm not quite sure how the change fixed your issue honestly, but seeing the exact config would make life easier.

Thanks!

Mark

--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To post to this group, send email to coldspri...@googlegroups.com.
To unsubscribe from this group, send email to coldspring-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldspring-users?hl=en.

Reply all
Reply to author
Forward
0 new messages