Wie kann ich Zuordnungen aus einer externen Eigenschaftendatei in Application.cfc einfügen?

Ich habe Probleme beim Einstellen von Zuordnungen in Application.cfc. Wir haben unterschiedliche Server (dev, QS, prod) mit jeweils etwas unterschiedlichen Pfaden. Ich möchte serverspezifische Pfade und Variablen über die Konfigurationsdatei festlegen. Bei ApplicationStart lesen Sie die INI-Datei und richten Ihr System ein.http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo Das funktioniert gut.

Normalerweise legen Sie die Zuordnungen in Applcation.cfc wie folgt fest:

<code><!--- in Application.cfc --->
<cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components">
</code>

Irgendwo in einer normalen cfm-Datei starte ich einen cfc-Test mit dem Namen:

<code><cfset t = createObject("component", "components.test")>
</code>

Ich möchte die Zuordnungen nur einmal auf setzenonApplicationsStart

<code><cffunction
    name="OnApplicationStart"
    access="public"
    returntype="boolean"
    output="false"
    hint="Fires when the application is first created.">

    <!---create structure to hold configuration settings--->
    <cfset ini = structNew()>
    <cfset ini.iniFile = expandPath("./ApplicationProperties.ini")>
    <cfset application.ini = ini>

    <!--- read ini file --->
    <cfset sections = getProfileSections(application.ini.iniFile)>

    <cfloop index="key" list="#sections.mappings#">
       <cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>
</code>

Aber das funktioniert nicht, weil this.mappings leer ist und die nächste Anfrage. :(

Putting this to OnRequestStart

<code><!--- read ini file --->
    <cfset sections = getProfileSections(application.ini.iniFile)>

    <cfloop index="key" list="#sections.mappings#">
       <cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>
</code>

Ich erhalte die Fehlermeldung, dass die Komponente nicht gefunden werden kann. Das ist merkwürdig.

Struktur in den Anwendungsbereich einfügen

<code>    <cfloop index="key" list="#sections.mappings#">
       <cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>
</code>

Wie rufe ich meine Komponente auf?

<code><cfset t = createObject("component", "application.components.test")>
</code>

Funktioniert nicht

Ich habe also 3 Ziele.

Lesen aller Pfade und Zuordnungen aus der INI-DateiLesen Sie sie einmal bei ApplicationStarteinfache Verwendung im Quellcode.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage