【发布时间】:2016-03-03 21:24:06
【问题描述】:
我在无法在浏览器上复制的日志中遇到问题。我每天会收到数百个
invalid component definition, can't find component [cfc.udf]
cfc 存储在应用程序上方一层的 cfc 文件夹中。这样许多应用程序就可以使用相同的 cfc。
文件夹结构:
---- cfc
--------- udf.cfc
---- myApp
--------- application.cfc
在 application.cfc 中,我使用了特定于应用程序的映射,因为这是在生产中的许多不同负载平衡服务器以及 QA 环境和本地测试环境中设置的,并保持它们全部同步是难的。
在 onRequestStart 中,我有一个函数每 5 分钟重新启动一次应用程序。它是由一位顾问提供的。我怀疑这是罪魁祸首,因为日志显示这些错误恰好每隔 5 分钟出现一次
<cfcomponent>
<cfset This.name = "myApp">
<cfset This.Sessionmanagement=true>
<cfset This.Sessiontimeout="#createtimespan(0,0,30,0)#">
<cfset this.mappings['/cfc'] = ExpandPath('../cfc')>
<cffunction name="onApplicationStart">
<cfset Application.udf = createObject("component", "cfc.udf").init()>
</cffunction>
<cffunction name="onRequestStart">
<cfset appRefreshMinutes = 5>
<cfif Not IsDefined("Application.refreshTime")>
<cfset currentMinute = Minute(Now())>
<cfset Application.refreshTime = DateAdd("n", -(currentMinute MOD appRefreshMinutes)+appRefreshMinutes, Now())>
<cfset Application.refreshTime = DateAdd("s", -(Second(Application.refreshTime)), Application.refreshTime)>
</cfif>
<cfif Now() GTE Application.refreshTime Or IsDefined("URL.reload")>
<cflock name="ApplicationInit" type="exclusive" timeout="5" throwontimeout="false">
<cfif Now() GTE Application.refreshTime Or IsDefined("URL.reload")>
<cfset OnApplicationStart()>
<cfset Application.refreshTime = DateAdd("n", appRefreshMinutes, Application.refreshTime)>
</cfif>
</cflock>
</cfif>
</cffunction>
</cfcomponent>
【问题讨论】:
-
您是否尝试过使用除
/cfc以外的映射名称?像<cfset this.mappings['/somethingelse'] = ExpandPath('../cfc')>这样你就可以像<cfset Application.udf = createObject("component", "somethingelse.udf").init()>这样称呼它。也许它看起来很奇怪...... -
我继续测试更改映射名称。现在我得等着看它是否会再次发生,因为我无法复制它
-
@Miguel-F:你是对的,是导致问题的映射名称。请将其作为答案提交,以便我接受它作为正确答案
-
会的。很高兴它解决了您的问题。
-
查看此帖子可能会解决您的问题:link
标签: coldfusion mapping cfc