I am able to duplicate Brian's issue using stable release 0.5. If I use constructor-arg to pass a bean, and have a private setter for that bean, it throws the error saying "The method 'setPersonGateway' could not be found in component".
 
If I change the setter to public access, no error. If I comment out the setter all together, no error.
 
As far as whether constructor-args or setter methods is better... It seems like I read in the CS documentation or something that the setter method is preferred. But I don't why that would be. Brian's point of if the component needs it, the let the init get it makes sense. And then the init calls the private setter. So having a private setter and a public getter for that bean would be logical.
 
My $.02


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Brian Kotek
Sent: Wednesday, April 05, 2006 7:46 AM
To: [email protected]
Subject: [coldspring-dev] Setter being called when passing bean as constructor-arg?

One additional bit of info is that CS IS passing the sessionManager into the constructor as I am specifying. The problem is that it is ALSO then trying to call the setSessionManager method anyway. I'm sure you're right Scott and it's getting a bit confused because there is a setSessionManager method, it's just private. I think the trick will be to tell the engine to skip attempts to call the setter if the "constructor-arg" is used and not "property". When I test it in 0.5 and/or create a simple test case that demonstrates the issue I'll alert you. Thanks.

On 4/4/06, Chris Scott < [EMAIL PROTECTED]> wrote:
AHHH. You have a setter, but it's private! I think ColdSpring is attempting to pick up that setter method and autowire your sessionManager, but of course, that method is private! Problem there is, well, we need to make sure we only pick up public methods, but ColdSpring matched a setter method with a bean it believes it can resolve a dependency for. Problem is, your setter is private, and ColdSpring wanted so very very hard to help you! OK, I'll add that to Jira...

Thanks, Chris

On Apr 4, 2006, at 7:57 PM, Brian Kotek wrote:

Hi Peter, yes I'm sure because if I go set the access attribute of setSessionManager() to public ColdSpring WILL call the setter method. I could probably live with this but it still seemed worth bringing up becuase I'm explictily telling CS to pass it as an argument to the constructor and not call the setter method (constructor-arg instead of property).

On 4/4/06, Peter J. Farrell < [EMAIL PROTECTED]> wrote:
Brian Kotek said the following on 4/4/2006 4:54 PM:
> Thanks Sean, yes I double checked all that even to the point of
> cutting and pasting the exact same argument name from the CFC to the
> ColdSpring XML:
>
>     <cffunction name="init" access="public" returntype="any"
> output="false"  hint="I perform all initialization">
>         <cfargument name="reactor"
> type="reactor.reactorFactory" required="true" />
>         <cfargument name="sessionManager" type="any" required="true"
> hint="Reference to the session manager." />
>         <cfset variables.instance = structNew() />
>         <cfscript>
>             setReactor( reactor=arguments.reactor );
>             setSessionManager(arguments.sessionManager );
>         </cfscript>
>         <cfreturn this />
>     </cffunction>
>
> Any other idears? Thanks.
I know this is a dumb question, but are you sure that your
setSessionManager() method is defined this service?  Check the spelling
etc.?

You might try adding something like this in your init() just to see if
CS is passing in the SessionManager:

<cfiif NOT StructKeyExists(arguments, "sessionManager")>
    <cfthrow type="appplication" message="I didn't get the session
manager from CS!"/>
</cfif>

I always try to prefer setter injection versus constructor-arg injection
if at all possible.  I only use constructor-arg inject the object
absolutely requires another object to init and may be consumed  by
another object on its' init.  You can always use property injection and
the have CS "setup" the service after all the dependencies have been
wired together.  Something like this:

<bean id="someService"
    class="someApp.model.sys.some.someService"
    init-method="setup">
    <property name="someDao"><ref bean="someDao"/></property>
    <property name="someGateway"><ref bean="someGateway"/></property>
    <property name="udfs"><ref bean="udfs"/></property>
</bean>

CS will call the init(), wire all the dependencies, then call all of the
init-methods (which in this case is setup()).

Best,
.Peter

--
Peter J. Farrell :: Maestro Publishing
Member Team Mach-II :: Member Team Fusion
http://blog.maestropublishing.com

Create boilerplate beans and transfer objects for ColdFusion!
Fire up a cup of Rooibos!
http://rooibos.maestropublishing.com/






Reply via email to