2013-06-25 6 views
5

Ich benutze Mule 3, um eine Datenbank mit JDBC abzufragen, und ich möchte die Abfrage abhängig von der Eingabe aus einer .properties-Datei ändern. Ich habe dies in meinem xml ...Mule 3 - Laden von Datei .properties

<context:property-placeholder location="C:\path\to\file\settings.properties" /> 

die folgende Ausnahme Erste ...

Exception in thread "main" org.mule.module.launcher.DeploymentInitException: SAXParseException: The prefix "context" for element "context:property-placeholder" is not bound. 

Muss ich einige spezielle XSD-Datei enthalten?

Antwort

7

Fügen Sie den xmlns Namespacepräfix und Schema Position zu Ihrem Mule Config-mule-Element-Tag.

Präfix:

xmlns:context="http://www.springframework.org/schema/context" 

schema:

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 

Es ist wie, wie unten aussehen sollte.

ZB:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:spring="http://www.springframework.org/schema/beans"  
    xmlns:http="http://www.mulesoft.org/schema/mule/http" 
    xmlns:context="http://www.springframework.org/schema/context" 

    xsi:schemaLocation=" 
     http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd 
     http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
     "> 


<context:property-placeholder location="C:/path/to/file/settings.properties" /> 


    ........... Other stuff 



</mule> 
+0

Danke. Das scheint das Namespace-Problem behoben zu haben, aber ich erhalte eine FileNotFound-Ausnahme, wenn die Datei eindeutig existiert. Haben Sie dieses Problem schon einmal erlebt? – Narabhut

+0

Neue Frage zu diesem Problem, hier ist der Link http://stackoverflow.com/questions/17326783/filenotfound-exception-while-loading-from-a-properties-file-in-mule Bitte überprüfen Sie, ob Sie lösen können – Narabhut

+0

Es gibt eine Antwort für Ihre Frage. Versuch es bitte. Das sollte es lösen. – user1760178

0

Die anderen Antworten bedeckt das Namespace Problem, aber ich werde hinzufügen, dass ich festgestellt, dass der Kontext: „: Bohnen spring“ Tags property-Platzhalter-Tag zwischen sein muß. Hier ist ein Beispiel, das davon ausgeht, dass die Eigenschaftsdatei eine Eigenschaft namens „jmsBrokerURL“ setzt:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
     xmlns:spring="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation=" 
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <spring:beans> 
     <context:property-placeholder location="C:/path/to/file/settings.properties" /> 
     <spring:bean name="myConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> 
      <spring:property name="brokerURL" value="${jmsBrokerURL}" /> 
     </spring:bean> 
    </spring:beans> 

    <flow name="MyFlow" doc:name="MyFlow"> 
     <!-- Flow configuration here. --> 
    </flow> 

</mule> 

Eine alternative Methode Eigenschaften des Lesens (und ich bevorzuge) ist die Feder verwenden „util: Eigenschaften“ Tag-Eigenschaften zu lesen in eine Properties-Bean, auf die Sie sich dann mit Spring EL beziehen. Achten Sie in diesem Fall darauf, dass Sie die Spring EL "# {}" Notation anstelle von "$ {}" verwenden, um auf das Objekt und seine Variablen zu verweisen. Hier ist das obige Beispiel für diese Technik modifiziert:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
     xmlns:spring="http://www.springframework.org/schema/beans" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xsi:schemaLocation=" 
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> 

    <spring:beans> 
     <util:properties id="myConfig" location="C:/path/to/file/settings.properties" /> 
     <spring:bean name="myConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> 
      <spring:property name="brokerURL" value="#{myConfig.jmsBrokerURL}" /> <!-- Note the pound (hash) symbol. --> 
     </spring:bean> 
    </spring:beans> 

    <flow name="MyFlow" doc:name="MyFlow"> 
     <!-- Flow configuration here. --> 
    </flow> 

</mule> 

Ich mag diese letztere Ansatz vor allem, weil ich mit mehreren Eigenschaften Dateien umgehen kann und enthalten Anwendungskontext Dateien leichter. Der Kontext: Eigenschaft-Platzhalter-Tag kann problematisch sein, wenn Sie mit mehreren Eigenschaftendateien arbeiten oder eine Anwendungskontextdatei in eine andere einschließen.

0

Einfach die Eigenschaftendatei unter Ressourcenordner und

Verwenden Sie dieses „Classpath: settings.properties“ in der Eigenschaft-Platzhalter und es wird funktionieren ...

4

Ich hatte die gleichen Probleme und es behoben . Hier, was ich getan habe.

  1. behielt alle .properties unter src/main/resources
  2. < Kontext: Objekt-Platzhalter location = "file.dev.properties, file.stage.properties" />
  3. alle Dateien Keeping im Klassenpfad war eine Herausforderung. Also Gehe zu deinem Projektordner, Öffnen.Classpath-Datei in Text-Pad und fügen Sie die folgende Zeile

    < classpathentry 
        including="file.dev.properties|file.prod.properties|file.stage.properties" 
        kind="src" path="src/main/resources"/ > 
    
  4. Speichern, aktualisieren und es funktioniert.
+0

+1 für Aktualisieren. –

Verwandte Themen