2013-06-25 11 views
5

Utilizzo Mule 3 per interrogare un database utilizzando JDBC e desidero modificare la query in base all'input da un file .properties. Ho questo nel mio xml ...Mule 3 - Caricamento da file .proprietà

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

Ottenere la seguente eccezione ...

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

Ho bisogno di includere alcuni file speciale .xsd?

risposta

7

aggiungere il prefisso xmlns spazio dei nomi e posizione dello schema al tag elemento di configurazione mulo Mulo.

Prefisso:

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

schemaLocation:

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

Esso dovrebbe essere simile come qui di seguito.

Esempio:

<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

Grazie. Sembra che abbia risolto il problema dello spazio dei nomi, ma sto ricevendo un'eccezione FileNotFound quando il file esiste chiaramente. Hai già riscontrato questo problema? – Narabhut

+0

Ha fatto una nuova domanda su questo problema, ecco il link http://stackoverflow.com/questions/17326783/filenotfound-exception-while-loading-from-a-properties-file-in-mule Si prega di vedere se è possibile risolvere – Narabhut

+0

C'è una risposta pubblicata per la tua domanda. Per favore provalo Questo dovrebbe risolverlo. – user1760178

0

Le altre risposte copriva il problema dello spazio dei nomi, ma io aggiungo che ho scoperto che il contesto: tag di proprietà-segnaposto bisogno di essere tra: tag "primavera fagioli". Ecco un esempio che presuppone che il file di proprietà di imposta una proprietà denominata "jmsBrokerURL":

<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> 

Un metodo alternativo per la lettura di proprietà (e quello che preferisco) è quello di utilizzare i Primavera "util: Proprietà" tag per leggere le proprietà in un bean Proprietà a cui si fa riferimento usando EL Spring. Fai attenzione in questo caso che usi la notazione EL "# {} di Spring invece di" $ {} "per fare riferimento all'oggetto e alle sue variabili. Ecco l'esempio precedente modificato per quella tecnica:

<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> 

mi piace questo secondo approccio soprattutto perché posso affrontare con i file più proprietà e file inclusi contesto applicativo più facilmente. Il contesto: il tag segnaposto di proprietà può essere problematico quando si ha a che fare con più file di proprietà o quando si include un file di contesto dell'applicazione all'interno di un altro.

0

Basta caricare il file delle proprietà nella cartella delle risorse e

utilizzare questo "percorso di classe: settings.properties" nella proprietà-segnaposto e funzionerà ...

4

ho avuto gli stessi problemi e riparato . Ecco cosa ho fatto.

  1. serbava tutte .properties sotto src/main/risorse
  2. < contesto: proprietà-segnaposto location = "file.dev.properties, file.stage.properties" />
  3. Mantenendo tutti i file in classpath era una sfida. Quindi vai alla cartella del tuo progetto, Apri.file classpath in text pad e aggiungi la riga sottostante

    < classpathentry 
        including="file.dev.properties|file.prod.properties|file.stage.properties" 
        kind="src" path="src/main/resources"/ > 
    
  4. Salvare, aggiornare e funziona.
+0

+1 per aggiornamento. –

Problemi correlati