このエラーが発生するなぜ私のCFファクトリオブジェクトで依存性注入が失敗しますか?
要素INSTANCEは可変では定義されていません。
エラーの原因は表示されません。
<cfset objectFactory = CreateObject("component","ObjectFactory").init()>
FYI、init()
と<cfcomponent>
はFYI output='false'
を、あなたがすべきである持っている必要があります。
は、これはあなたがObjectFactoryのインスタンス化時には、init()を呼び出していることを確認してください私の工場
<cfcomponent output="true" displayname="ObjectFactory">
<cffunction name="init" access="public" output="true" returntype="ObjectFactory">
<cfset variables.instance = structNew() />
<cfreturn this />
</cffunction>
<cffunction name="createObj" access="public" output="false" returntype="any">
<cfargument name="objName" type="string" required="true" />
<cfswitch expression="#arguments.objName#">
<cfcase value="abstractCollection">
<cfreturn createObject('component',"AbstractCollection").init() />
<cfbreak />
</cfcase>
<cfcase value="assignmentCollection">
<cfreturn createObject('component',"AssignmentCollection").init() />
<cfbreak />
</cfcase>
<cfcase value="salesmanBean">
<cfreturn createObject('component',"SalesmanBean").init(
salesmanHasThisDecorations = this.getInstance("assignmentCollection")) />
<cfbreak />
</cfcase>
</cfswitch>
</cffunction>
<cffunction name="getInstance" access="public" output="false" returntype="any">
<cfargument name="objName" type="string" required="true" />
<!--- Error occurs in the line below --->
<cfif not structKeyExists(variables.instance, arguments.objName)>
<cfset variables.instance[arguments.objName] = this.createObj(arguments.objName) />
</cfif>
<cfreturn variables.instance[arguments.objName] />
</cffunction>
</cfcomponent>
このようにして解決しました。 –
mrt181