FileNotFound exception while loading from a .prope

2019-09-06 17:39发布

问题:

I'm trying to load values from a .properties file in Mule and I get a FileNotFound exception when the file clearly exists. I've tried putting the file inside the project directory, using relative path but nothing works.

Here is relevant stuff from my Mule flow -

<?xml version="1.0" encoding="UTF-8"?>

<mule 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:file="http://www.mulesoft.org/schema/mule/file" 
xmlns="http://www.mulesoft.org/schema/mule/core" 
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 
xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" 
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:core="http://www.mulesoft.org/schema/mule/core" 
version="EE-3.4.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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" />

<oracle data source info />
<connector info />
<flow name="temp" doc:name="Temp" >
<other stuff />
</flow>
</mule>

Is there any way to get past this issue?

回答1:

Put settings.properties file in your classpath (directly under src/main/resources/ in your project) and refer it like this:

<context:property-placeholder location="settings.properties" />



回答2:

The context property place holder look by default into the classpath.

Use the following configuration to look for a file in the physical path your file exists.

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

This should work.

The most preferred approach is to keep the properties file in the project classpath.

Hope this helps.



回答3:

Place the properties file in class path like app/main/src. It will work For more information related to propertied file take a look at below link.

https://docs.mulesoft.com/mule-user-guide/v/3.5/configuring-properties