【问题标题】:Invalid Component Definition无效的组件定义
【发布时间】: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 以外的映射名称?像&lt;cfset this.mappings['/somethingelse'] = ExpandPath('../cfc')&gt; 这样你就可以像&lt;cfset Application.udf = createObject("component", "somethingelse.udf").init()&gt; 这样称呼它。也许它看起来很奇怪......
  • 我继续测试更改映射名称。现在我得等着看它是否会再次发生,因为我无法复制它
  • @Miguel-F:你是对的,是导致问题的映射名称。请将其作为答案提交,以便我接受它作为正确答案
  • 会的。很高兴它解决了您的问题。
  • 查看此帖子可能会解决您的问题:link

标签: coldfusion mapping cfc


【解决方案1】:

由 cmets 推广

您是否尝试过使用/cfc 以外的映射名称?喜欢:

<cfset this.mappings['/somethingelse'] = ExpandPath('../cfc')>

这样你就可以这样称呼它:

<cfset Application.udf = createObject("component", "somethingelse.udf").init()>

也许它对我来说看起来很奇怪,或者这可能导致您的问题(cfc 是保留字或在这种情况下以某种方式得到特殊处理)。

【讨论】:

  • Miguel-F,对不起,我错了。这不是问题。我认为这是因为我停止收到错误消息,但我停止收到错误的原因是因为我搞砸了并在 onrequeststart 方法中发送了带有 cfabort 的 application.cfc 的副本。哎呀。 20分钟后,我接到客户的愤怒电话。现在,我得到了无效的组件定义,找不到组件 [somethingelse.udf]。我将尝试将应用程序的 cfdump 放在错误日志中。
  • 很抱歉。请发布您的解决方案以避免任何混淆。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-26
  • 2021-05-26
  • 1970-01-01
  • 2020-04-30
  • 2018-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多