2013-06-25 26 views
5

Tôi đang sử dụng Mule 3 để truy vấn cơ sở dữ liệu bằng JDBC và tôi muốn sửa đổi truy vấn tùy thuộc vào đầu vào từ tệp .properties. Tôi có điều này trong xml của tôi ...Mule 3 - Đang tải từ tệp .properties

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

Lấy ngoại lệ sau đây ...

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

Tôi có cần phải bao gồm một số tập tin XSD đặc biệt không?

Trả lời

7

Thêm tiền tố xmlns namespace và vị trí schema để tag yếu tố cấu hình con la Mule của bạn.

Prefix:

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 

Nó sẽ giống như như dưới đây.

Ví dụ:

<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

Cảm ơn. Điều đó dường như đã sửa vấn đề không gian tên nhưng tôi nhận được một ngoại lệ FileNotFound khi tệp tồn tại rõ ràng. Bạn đã từng gặp phải vấn đề này chưa? – Narabhut

+0

Đã tạo một câu hỏi mới về vấn đề này, đây là liên kết http://stackoverflow.com/questions/17326783/filenotfound-exception-while-loading-from-a-properties-file-in-mule Vui lòng xem liệu bạn có thể giải quyết không – Narabhut

+0

Có một câu trả lời được đăng cho câu hỏi của bạn. Hãy thử nó. Điều đó sẽ giải quyết nó. – user1760178

0

Những câu trả lời khác bao gồm các vấn đề không gian tên, nhưng tôi sẽ thêm rằng tôi thấy rằng bối cảnh: Thẻ tài sản giữ chỗ cần thiết để được giữa "mùa xuân: đậu" thẻ. Dưới đây là một ví dụ mà giả định rằng các tập tin thuộc tính thiết lập một tài sản có tên là "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> 

Một phương pháp thay thế của việc đọc tài sản (và một Tôi thích) là sử dụng mùa xuân "util: thuộc tính" tag để đọc thuộc tính vào một bean Properties mà sau đó bạn sử dụng Spring EL. Chú ý trong trường hợp này, bạn sử dụng ký hiệu "EL" # {} "thay vì" $ {} "để tham chiếu đối tượng và các biến của nó. Dưới đây là ví dụ trên được sửa đổi cho kỹ thuật đó:

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

Tôi thích phương pháp sau này chủ yếu vì tôi có thể xử lý nhiều tệp thuộc tính và tệp ngữ cảnh ứng dụng bao gồm dễ dàng hơn. Ngữ cảnh: thẻ trình giữ chỗ thuộc tính có thể có vấn đề khi xử lý nhiều tệp thuộc tính hoặc khi bao gồm tệp ngữ cảnh ứng dụng trong một tệp khác.

0

Chỉ cần đặt các thuộc tính tập tin trong thư mục nguồn và

Sử dụng này "classpath: settings.properties" trong tài sản giữ chỗ và nó sẽ làm việc ...

4

tôi đã có vấn đề tương tự và cố định nó . Đây là những gì tôi đã làm.

  1. giữ tất cả .properties dưới src/main/nguồn
  2. < bối cảnh: tài sản giữ chỗ vị trí = "file.dev.properties, file.stage.properties" />
  3. Giữ tất cả các file trong classpath là một thử thách. Vì vậy, Goto thư mục dự án của bạn, Mở.tệp classpath trong văn bản pad và thêm dòng dưới đây

    < classpathentry 
        including="file.dev.properties|file.prod.properties|file.stage.properties" 
        kind="src" path="src/main/resources"/ > 
    
  4. Lưu, làm mới và hoạt động.
+0

+1 để làm mới. –

Các vấn đề liên quan