Spring 在 weblogic 上激活时启动应用程序错误

Spring boot application error when activating on weblogic

场景:

我有一个 Spring 引导应用程序,其中包含 4 个 maven 配置文件和 5 个不同的 application.properties 文件(例如 application-dev.properties)(4 个用于 maven 配置文件,1 个用于默认配置文件). 测试和生产 Maven 配置文件具有几乎相同的设置,不同之处在于域、文本等。 我们有 2 个 Weblogic 服务器,具有相同的配置和 JNDI。一个用于测试,一个用于生产。

问题:

test Weblogic 服务器上部署和激活应用程序时(在构建时选择测试 maven 配置文件),部署和.war 激活成功。应用运行良好,皆大欢喜

production Weblogic 服务器(使用生产 maven 配置文件)上部署和激活应用程序时,部署正常,但是激活 .war 时它会 FAILED 并出现以下错误。

    weblogic.application.ModuleException: java.lang.IllegalArgumentException: Could not resolve placeholder 'xxxxxxxx' in value "${xxxxxxxx}"

        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)

        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)

        at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:233)

        at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:228)

        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)

        Truncated. see log file for complete stacktrace

Caused By: java.lang.IllegalArgumentException: Could not resolve placeholder 'xxxxxxxx' in value "${xxxxxxxx}"

        at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)

        at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)

        at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236)

        at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210)

        at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties[=11=](PropertySourcesPlaceholderConfigurer.java:175)

        Truncated. see log file for complete stacktrace

一开始我以为是production maven profile的问题,后来尝试在测试Weblogic中用production profile部署激活app,一切正常。

我也尝试检查 setDomainEnv.sh Weblogic 环境变量的差异,但它们是相同的。

有什么想法吗?

好的,由于某些未知原因,在生产 weblogic 服务器中,当激活 .war 时,weblogic 尝试从仅包含 spring.profiles.active=prod 的 application.properties 文件中解析占位符. 所以通常 Spring 应该在 application-prod.properties 中找到属性(在测试 weblogic 服务器上工作)。

解决方案

在连续 2 天做了一些 RnD 之后,无法理解为什么这不起作用,我尝试了一个可行的解决方案。 我用 application-[=34 的内容替换了 application.properties 内容(spring.profiles.active 行) =].

我知道,最好的解决方案是找出为什么 spring.profiles.active 在生产 weblogic 上不起作用。但我写这篇 post 只是为了帮助其他有截止日期的人如何快速解决问题。

我希望 Spring 比我更有经验的人解释为什么会这样。