from the docs:
"A name of a method that ColdSpring will call on a bean after all its
dependencies have been set."
http://www.coldspringframework.org/docs/BeanFactory_Reference.htm#_bean___tag_attributes
On 7/9/07, Brian Kotek <[EMAIL PROTECTED]> wrote:
I've never heard of this init-method thing. To get ColdSpring to inject your
Articles component you just need a setter in your Category component.
ColdSpring matches the name of the property to the setter (so property
Articles looks for setter setArticles). So make sure in your XML the name of
the property matches the name used in the setter.
<cffunction name="setArticles" access="public" returntype="void"
hint="Articles setter">
<cfargument name="articlesCFC" type="Components.Articles "
required="true" />
<cfset Variables.articlesCFC = arguments.articlesCFC />
</cffunction>
On 7/9/07, Jonathon Stierman <[EMAIL PROTECTED]> wrote:
> Anyone have any examples of how this is used? I've got a circular
> dependency that I'd like to resolve by using this.
>
> I got a response from Peter Farrell, in a past thread:
>
> >> <bean name="someService" id="dot.path.to.someService"
> init-method="setup">
> >> <property name="someOtherService"><ref
bean="someOtherService"/></bean>
> >> <property name="thatService"><ref bean=""thatService"/></bean>
> >> </bean>
> >>
> >> Order of operations:
> >> 1. Create someService
> >> 2. Call init() with any constructor args (must resolve dependencies
> first)
> >> 3. Wiring in properties
> >> 4. Call init-method (yes, it's a misleading name, but it follows the
> Spring DTD here). In my architecture, we
> >> call this the setup() method.
>
> I figured ColdSpring would just run some magic on my properties and
> automatically figure out that they should be set in the init-method rather
> than in the init() constructor, but CS threw an error at me indicating it
> was still looking for a generic set[myDependency]() method. Here's my
> config.xml:
>
> <!-- File loaded by ColdSpring to perform dependency injection -->
> <beans>
> <bean id="Articles" class="Components.Articles" singleton="true">
> <constructor-arg
>
name="datasource"><value>${datasource}</value></constructor-arg>
> </bean>
> <bean id="Categories" class=" Components.Categories"
singleton="true"
> init-method="setup">
> <constructor-arg
>
name="datasource"><value>${datasource}</value></constructor-arg>
> <property name="articleCFC"><ref bean="Articles"
> /></property>
> </bean>
> </beans>
>
> And here's my Categories.cfc:
>
> <cfcomponent hint="Add/Edit/Delete Categories">
> <cfset Variables.datasource = "" />
> <cfset Variables.articlesCFC = "" />
>
> <cffunction name="init" access="public"
> returntype="Components.Categories" hint="I initialize myself">
> <cfargument name="datasource" type="string"
> required="false" />
>
> <cfset Variables.datasource = arguments.datasource />
>
> <cfreturn this />
> </cffunction>
>
> <cffunction name="setup" access="public"
> returntype="Components.Categories" hint="I post-initilize myself for
> circular dependencies">
> <cfargument name="articlesCFC"
> type="Components.Articles" required="false" />
>
> <cfset Variables.articlesCFC = arguments.articlesCFC />
>
> <cfreturn this />
> </cffunction>
> </cfcomponent>
>
> What's the syntax for making the init-method concept work? I googled
around
> a bit, but kept getting matches regarding the regular init() constructor
> rather than the init-method usage.
>
> Jonathon
>
>
>
>