2014-06-25 80 views
1

我正在關注spring引導項目的示例。 我已經通過maven編譯並創建了一個jar文件,但在運行嘗試時出現錯誤。Spring Boot示例FileNot發現錯誤

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple

項目文件夾: enter image description here

錯誤:

Java的罐子彈簧引導樣本簡單1.1.3.BUILD-SNAPSHOT.jar

014-06-25 09:10:00.653 ERROR 12028 --- [   main] o.s.boot.SpringApplication    : Application startup failed 

ava.lang.IllegalStateException: Unable to load configuration files 
     at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:158) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.j 
va:138) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.j 
va:131) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:120) 
     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98) 
     at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100) 
     at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:59) 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:277) 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:944) 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:933) 
     at sample.simple.SampleSimpleApplication.main(SampleSimpleApplication.java:46) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source) 
     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53) 
     at java.lang.Thread.run(Unknown Source) 
aused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist 
     at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) 
     at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:132) 
     at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:121) 
     at org.springframework.boot.env.PropertiesPropertySourceLoader.load(PropertiesPropertySourceLoader.java:44) 
     at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:126) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:360) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:349) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:317) 
     at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:155) 
     ... 16 common frames omitted 
+0

'application.properties'應該位於src \ main \ resources'文件夾中 –

回答

0

您錯過的application.properties文件。使用Spring Boot,您可以將此文件放置在與jar文件相同的級別,並使用該文件。查看文檔以獲得更多信息link here

+0

但是spring會在classpath中搜索屬性文件springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)。而application.properties文件位於jar文件中意味着它在classpath/ –

1

有一個bug in Spring Boot 1.1.2,當您嘗試從jar文件運行您的應用程序時,會在Windows上導致類加載問題。我建議回到1.1.1直到它被修復。

+0

中遇到了同樣的問題。這幫助了我,謝謝。 – cuttcards

+0

[Spring Boot 1.1.3](https://spring.io/blog/2014/06/27/spring-boot-1-1-3-available-now)已經發布來解決這個問題。 – ebell

相關問題