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.
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
Đã 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
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