Springboot 初始化依赖 Liberty application.xml 并显示类路径未知异常

Springboot initialization depends on Liberty application.xml and showing classpath unknown exception

我试图在 WebSphere Liberty Core 18.0.0.2 中部署我的 springboot 应用程序。我在服务器中有两个 xml 文件 - server.xmlapplication.xmlapplication.xml 包含特定于应用程序的配置,如下所示。

<library description="Oracle JDBC Library" id="OracleJDBCLib" name="OracleJDBCLib">
    <fileset dir="${shared.resource.dir}/jdbc/oracle" includes="*.jar"/>
</library>
<jdbcDriver id="OracleProvider" libraryRef="OracleJDBCLib"/>

 <springBootApplication contextRoot="/provider" id="provider" location="provider-exec.war" type="war">
     <classloader commonLibraryRef="OracleJDBCLib"  />
</springBootApplication>

它被包含在 server.xml

<include location="${server.output.dir}/application.xml" optional="true" onConflict="MERGE"/>

问题是 springboot 将此 application.xml 用于 bean 初始化,这不应该发生。根据我的理解,springboot war 是自包含的,它不会寻找特定于容器的配置。

为了验证,我已将 application.xml 重命名为 springbootapp.xml 并且有效。应用程序运行良好。

如果需要更改任何配置以限制 springboot 不查找特定于容器的配置,请告诉我?

虽然不是技术上的答案,但请注意,您可以通过声明 Spring 引导应用程序属性 server.contextPathserver.servlet.contextPath 来更改 Spring 引导应用程序的根上下文路径在 <springBootApplication><applicationArgument> 范围内。假设 Spring Boot 2.0 应用程序,试试这个。

<variable name="springBoot15AppArg1" value="--server.contextPath=/provider"/>
<variable name="springBoot20AppArg1" value="--server.servlet.contextPath=/provider"/>

<springBootApplication location="provider-exec.war">
    <applicationArgument>${springBoot20AppArg1}</applicationArgument>
</springBootApplication>

参考:https://www.ibm.com/support/knowledgecenter/en/SSEQTP_liberty/com.ibm.websphere.wlp.doc/ae/twlp_dep_sb_apparguments.html

如 Spring 引导参考指南 (Externalized Configuration) 中所述,它将查找名为 application.properties 的文件。然而他们没有告诉你的是,这也可能是 application.xml 而不是 application.properties

一个java.util.Properties object can be either loaded from a .properties or .xml文件。 Spring(因此 Spring Boot)对此有隐式支持。

简而言之,配置加载将检测 application.propertiesapplication.yml,但也会检测 application.xml

要修复你可以做两件事

  1. 重命名文件(如您所做)
  2. 将其移出类路径的根目录,并将其放入 META-INF 中。