由于 bean 命名冲突,Spring Boot 应用程序无法运行

lak*_*ren 7 java spring maven spring-boot

我收到此错误:

APPLICATION FAILED TO START
***************************

Description:

Configuration property name 'appConfig.baseVersion' is not valid:

    Invalid characters: 'C'
    Bean: paymentCheckoutRequestBuilder
    Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a letter

Action:

Modify 'appConfig.baseVersion' so that it conforms to the canonical names requirements.

Run Code Online (Sandbox Code Playgroud)

paymentCheckoutRequestBuilder 是 PaymentCheckoutRequestBuilder 类的一个 bean。我该怎么解决这个问题,你不能在烤肉串中命名一个类。

此外,在我尝试将 spring-boot 升级到 2.2.0 后发生此错误。

这个 appConfig.baseVersion 是什么,在网上找不到任何东西。

rec*_*ion 6

属性 appConfig.baseVersion 采用驼峰式大小写,因此您应该在配置中使用 use 前缀,如下所示

     mqConfig:
         enable: false
     
Run Code Online (Sandbox Code Playgroud)

那么你的配置文件必须有@ConfigurationProperties(prefix = "mq-config")

对于当前示例,application.yaml 应该是

appConfig:
   baseVersion: 1
Run Code Online (Sandbox Code Playgroud)

而java类应该是

@Configuration
@ConfigurationProperties(prefix = "app-config")
public class TestConfig {
  int baseVersion;
 }
Run Code Online (Sandbox Code Playgroud)

还有


小智 4

这是不言自明的: 原因:规范名称应该是短横线大小写 请注意,@ConfigurationProperties 不应该采用驼峰式大小写。因此,您应该修复目标 bean 的 @ConfigurationProperties 前缀。