我嘗試在JBossFuse/karaf上加載運行在Java中的屬性文件。從Jboss Fuse/Karaf文件系統中加載屬性文件Nullpointer
該文件位於$ [karaf.home] /etc/bean.properties
的代碼能夠加載包裏面罰款性質,但現在我試圖排除來自項目本身的屬性和該代碼會拋出一個空指針異常。
的路徑是正確的決定,我的開發機器上
C:\用戶\人\ DEVSTUDIO \運行時\ jboss的熔絲,6.3.0.redhat-135 \等\ bean.properties
可以在blueprint-XML中加載屬性File以配置Bean,但要訪問Bean,我的代碼需要CamelContext。由於我有一些沒有交換/上下文/註冊表的靜態代碼塊,我還希望能夠加載Java中的屬性。
兩種功能拋出NullPointerException異常,我想,那是因爲在代碼運行保險絲。
public static Properties getProperties(String location) {
Properties prop = new Properties();
InputStream input = null;
try {
input = PropertyLoader.class.getClassLoader().getResourceAsStream(location);
prop.load(input);
} catch (IOException ex) {
log.error("Error loading properties file from: " + location, ex);
return null;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
log.error(e);
}
}
}
return prop;
}
public static Properties getPropertiesFromFilesystem(String location) {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(location);
prop.load(input);
} catch (IOException ex) {
log.error("Error loading properties file from: " + location, ex);
return null;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
log.error(e);
}
}
}
return prop;
}
除外:
顯示java.lang.NullPointerException 在java.util.Properties $ LineReader.readLine(Properties.java:434)[:1.8.0_91] 在java.util中.Properties.load0(Properties.java:353)[:1.8.0_91] 在java.util.Properties.load(Properties.java:341)[:1.8.0_91] 在com.mycompany.util.PropertyLoader.getProperties (PropertyLoader.java:19)[319:camel-archetype-blueprint:0.0.14] at com.mycompany.camel.blueprint.MyProcessor.process(MyProcessor.java:21)[319:camel-原型-藍圖:0.0.14] 在org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)[231:org.apache.camel.camel核:2.17.0.redhat-630135] 在org.apache.camel.processor的org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[231:org.apache.camel.camel-core:2.17.0.redhat-630135] 。 RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)[231:org.apache.camel.camel核:2.17.0.redhat-630135]在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196 )[231:org.apache.camel.camel-core:2.17.0.redhat-630135] at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[231:org.apache.camel .camel-core:2.17.0.redhat-630135] at org.apache.camel.processor.Pipeline.process(Pipeline的.java:83)[231:org.apache.camel.camel核:2.17.0.redhat-630135]在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[231:有機.apache.camel.camel核:2.17.0.redhat-630135]在 org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192)[231:org.apache.camel.camel- core:2.17.0.redhat-630135] at org.apache.camel.component.timer.TimerConsumer $ 1.run(TimerConsumer.java:76)[231:org.apache.camel.camel-core:2.17.0。 redis-630135] at java.util.TimerThread.mainLoop(Timer.java:555)[:1.8.0_91] at java.util.TimerThread.run(Timer.java:505)[:1.8.0_91]
任何幫助將不勝感激。
鑑於您的意見,我強烈建議您閱讀「OSGi in Action」一書 –