Spring 引导无法从位置 'classpath:/application.xml' 加载 属性 源

Spring Boot failed to load property source from location 'classpath:/application.xml'

当我在 Jboss 7.x EAP 中部署打包在 ear 中的 Spring 启动应用程序时,我收到以下错误:

server.default-host./pepe: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./pepe: java.lang.RuntimeException: java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:231)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:82)
... 6 more
Caused by: java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:476)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:386)
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:225)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:195)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:168)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:184)

耳朵的结构如下:

├── META-INF
│   ├── application.xml
│   └── jboss-deployment-structure.xml
├── evaluateboot_be-web-0.0.1-SNAPSHOT.war
└── lib
    ├── asm-5.0.4.jar
    ├── aspectjweaver-1.8.13.jar
    ├── bcpkix-jdk15on-1.55.jar
    ├── bcprov-jdk15on-1.55.jar
    ├── bval-core-1.1.2.jar
    ├── cache-api-1.0.0.jar
    ├── ccf2-8.0.0.4_MAPFRE.jar  
    ├── cxf-core-3.1.12.jar
    ├── cxf-rt-bindings-soap-3.1.12.jar
    ├── cxf-rt-databinding-jaxb-3.1.12.jar
    ├── cxf-rt-frontend-jaxws-3.1.12.jar
    ├── cxf-rt-frontend-simple-3.1.12.jar
    ├── cxf-rt-security-3.1.12.jar
    ├── cxf-rt-security-saml-3.1.12.jar
    ├── cxf-rt-transports-http-3.1.12.jar
    ├── cxf-rt-ws-security-3.1.12.jar
    ├── cxf-rt-wsdl-3.1.12.jar
    ├── cxf-spring-boot-autoconfigure-3.1.12.jar
    ├── cxf-spring-boot-starter-jaxws-3.1.12.jar
    ├── dom4j-1.6.1.jar
    ├── ehcache-2.10.4.jar
    ├── evaluateboot-bo-0.0.1-SNAPSHOT.jar
    ├── evaluateboot_be-commons-0.0.1-SNAPSHOT.jar
    ├── evaluateboot_be-crud-dl-api-0.0.1-SNAPSHOT.jar
    ├── evaluateboot_be-crud-sr-api-0.0.1-SNAPSHOT.jar
    ├── evaluateboot_be-crud-sr-impl-0.0.1-SNAPSHOT.jar
    ├── evaluateboot_be.zeroConfig-0.0.1-SNAPSHOT.jar
    ├── guava-19.0.jar
    ├── hibernate-validator-5.3.6.Final.jar
    ├── httpclient-4.5.3.jar
    ├── httpcore-4.4.8.jar
    ├── jackson-annotations-2.8.0.jar
    ├── jackson-core-2.8.10.jar
    ├── jackson-databind-2.8.10.jar
    ├── jasypt-1.9.2.jar
    ├── jaxen-1.1.1_CXF_MAPFRE.jar
    ├── jboss-logging-3.3.1.Final.jar
    ├── jcl-over-slf4j-1.7.25.jar
    ├── jdom-1.1.jar
    ├── joda-time-2.9.9.jar
    ├── jul-to-slf4j-1.7.25.jar
    ├── log4j-over-slf4j-1.7.25.jar
    ├── logback-classic-1.1.11.jar
    ├── spring-aspects-4.3.13.RELEASE.jar
    ├── spring-beans-4.3.13.RELEASE.jar
    ├── spring-boot-1.5.9.RELEASE.jar
    ├── spring-boot-actuator-1.5.9.RELEASE.jar
    ├── spring-boot-autoconfigure-1.5.9.RELEASE.jar
    ├── spring-boot-starter-1.5.9.RELEASE.jar
    ...

我使用的spring引导版本是1.5.9。

为什么 Spring Boot 试图加载位于 META-INF 文件夹中的 ear 部署描述符?

这只耳朵在 Websphere 8.5 中正确部署。5.x

实际上 application.xml 和 jboss-deployment-structure.xml 文件应该存在于 WEB-INF 中。你能检查一下项目结构吗?如果是新项目,可以使用这个URL(https://start.spring.io/)来创建项目结构。可以参考下面的URL:

https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/ch01s04s02.html

验证包括 war 包装在内的完整结构。

仔细查看生成的工件后,我发现导致此错误的问题是因为其中一个工件具有以下插件:

<plugin>
  <groupId> org.apache.maven.plugins </ groupId>
     <artifactId> maven-jar-plugin </ artifactId>
       <configuration>
          <archive>
             <manifest>
               <addClasspath> true </ addClasspath>
             </ manifest>
            <manifestEntries>
               <Class-Path> ./ META-INF / </ Class-Path>
            </ manifestEntries>
       </ archive>
    </ configuration>
 </ plugin>

这导致它生成 META-INF 文件:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: jose
Class-Path: ./ META-INF/ bval-core-1.1.2.jar gaia-core-2.4.0-SNAPSHOT.
jar gaia-commons-devutils-2.4.0-SNAPSHOT.jar gaiafrontend-proxy-2.4.0
-SNAPSHOT.jar gaia-commons-2.4.0-SNAPSHOT.jar MAPFRE_ARQOS_CORE_VIDA.
 ArquitecturaCoreVidaFramework-14.1.12.jar MAPFRE_ARQOS_COMMONS_STANDA
LONE.CommonsExceptions-14.1.12.jar MAPFRE_ARQOS_COMMONS_STANDALONE.En
cryptionServiceProvider-14.1.12.jar MAPFRE_ARQOS_COMMONS_STANDALONE.U
tils-14.1.12.jar MAPFRE_ARQOS_COMMONS_STANDALONE.Log4M-14.1.12.jar MA
PFRE_ARQOS_COMMONS_STANDALONE.CacheServiceProvider-14.1.12.jar MAPFRE
_ARQOS_COMMONS_STANDALONE.Tron21ConnectorErrorExchange-14.1.12.jar do
m4j-1.6.1.jar jaxen-1.1.1_CXF_MAPFRE.jar xercesImpl-2.8.0.jar jdom-1.
1.jar ctgclient-8.0.0.4_MAPFRE.jar ctgserver-8.0.0.4_MAPFRE.jar ccf2-
8.0.0.4_MAPFRE.jar cicseci-8.0.0.4_MAPFRE.jar cicsecitools-8.0.0.4_MA
PFRE.jar cicsframe-8.0.0.4_MAPFRE.jar security-8.0.0.4_MAPFRE.jar spr
ing-aspects-4.3.13.RELEASE.jar spring-core-4.3.13.RELEASE.jar commons
-logging-1.2.jar spring-context-4.3.13.RELEASE.jar spring-context-sup
port-4.3.13.RELEASE.jar spring-beans-4.3.13.RELEASE.jar spring-expres
sion-4.3.13.RELEASE.jar spring-aop-4.3.13.RELEASE.jar spring-oxm-4.3.
13.RELEASE.jar spring-tx-4.3.13.RELEASE.jar spring-web-4.3.13.RELEASE
.jar spring-webmvc-4.3.13.RELEASE.jar spring-security-core-4.2.3.RELE
ASE.jar aopalliance-1.0.jar spring-security-ldap-4.2.3.RELEASE.jar sp
ring-ldap-core-2.3.2.RELEASE.jar spring-security-config-4.2.3.RELEASE
.jar spring-security-web-4.2.3.RELEASE.jar spring-boot-1.5.9.RELEASE.
jar spring-boot-autoconfigure-1.5.9.RELEASE.jar jackson-core-2.8.10.j
ar jackson-databind-2.8.10.jar jackson-annotations-2.8.0.jar cxf-core
-3.1.12.jar woodstox-core-asl-4.4.1.jar stax2-api-3.1.4.jar xmlschema
-core-2.2.2.jar cxf-rt-bindings-soap-3.1.12.jar cxf-rt-databinding-ja
xb-3.1.12.jar cxf-rt-frontend-simple-3.1.12.jar cxf-rt-frontend-jaxws
-3.1.12.jar asm-5.0.4.jar cxf-rt-transports-http-3.1.12.jar cxf-rt-ws
-security-3.1.12.jar cxf-rt-security-saml-3.1.12.jar cxf-rt-security-
3.1.12.jar wss4j-policy-2.1.10.jar neethi-3.0.3.jar wss4j-ws-security
-stax-2.1.10.jar wss4j-bindings-2.1.10.jar wss4j-ws-security-policy-s
tax-2.1.10.jar cxf-rt-wsdl-3.1.12.jar wsdl4j-1.6.3.jar logback-core-1
.1.11.jar logback-classic-1.1.11.jar slf4j-api-1.7.25.jar commons-io-
2.4.jar commons-codec-1.10.jar commons-pool-1.6.jar commons-lang-2.6.
jar commons-lang3-3.3.2.jar commons-collections-3.2.2.jar commons-bea
nutils-1.9.3.jar validation-api-1.1.0.Final.jar cache-api-1.0.0.jar j
oda-time-2.9.9.jar swagger-annotations-1.5.10.jar lombok-1.16.18.jar 
guava-19.0.jar aspectjweaver-1.8.13.jar coherence-12.1.2.0.jar ehcach
e-2.10.4.jar wss4j-1.6.7.jar wss4j-ws-security-common-2.0.9.jar xmlse
c-2.0.7.jar jasypt-1.9.2.jar wss4j-ws-security-dom-2.0.9.jar gaiaback
end-core-2.4.0-SNAPSHOT.jar gaia-context-2.4.0-SNAPSHOT.jar spring-jd
bc-4.3.13.RELEASE.jar springfox-swagger2-2.6.1.jar swagger-models-1.5
.10.jar springfox-spi-2.6.1.jar springfox-core-2.6.1.jar springfox-sc
hema-2.6.1.jar springfox-swagger-common-2.6.1.jar springfox-spring-we
b-2.6.1.jar classmate-1.3.4.jar spring-plugin-core-1.2.0.RELEASE.jar 
spring-plugin-metadata-1.2.0.RELEASE.jar mapstruct-1.0.0.Final.jar sp
ringfox-swagger-ui-2.6.1.jar gaiabackend-remote-2.4.0-SNAPSHOT.jar ga
ia-plinvoker-2.4.0-SNAPSHOT.jar plinvoker-1.0.0-20180208.232239-4.jar
cxf-spring-boot-starter-jaxws-3.1.12.jar spring-boot-starter-1.5.9.R
ELEASE.jar spring-boot-starter-logging-1.5.9.RELEASE.jar jul-to-slf4j
-1.7.25.jar log4j-over-slf4j-1.7.25.jar snakeyaml-1.17.jar spring-boo
t-starter-web-1.5.9.RELEASE.jar spring-boot-starter-tomcat-1.5.9.RELE
ASE.jar tomcat-embed-core-8.5.23.jar tomcat-annotations-api-8.5.23.ja
r tomcat-embed-el-8.5.23.jar tomcat-embed-websocket-8.5.23.jar hibern
ate-validator-5.3.6.Final.jar jboss-logging-3.3.1.Final.jar cxf-sprin
g-boot-autoconfigure-3.1.12.jar jcl-over-slf4j-1.7.25.jar
Created-By: Apache Maven 3.5.0
Build-Jdk: 1.8.0_20

正在从插件中删除条目:

<manifestEntries>
    <Class-Path> ./ META-INF / </ Class-Path>
</ manifestEntries>

不再扫描耳设备的application.xml文件