admin管理员组

文章数量:1353578

I can't post real code but this is a modified version of what I'm seeing, with fake class names. On startup of my Spring application, I see this log:

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

Description:

Parameter 1 of constructor in com.package.MyClass required a single bean, but 2 were found:
    - MyClass: defined in URL [jar:file:/var/lib/jenkins/workspace/.../com/package/MyClass.class]
    - fop.factory.pool-com.package.MyClass: defined in unknown location

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag.
You may need to update both your build tool settings as well as your IDE.
[See .x~ILparameter-name-retention]

Was looking at 3.4 release notes (.4-Release-Notes) and it looks like this is the offending change: Registered @ConfigurationProperties beans now respect @DependsOn, @Description, @Fallback, @Lazy, @Primary, @Scope and @Role annotations.. Below is the failing class, which is using @Primary and @ConfigurationProperties in tandem:

@Component
@Primary
@ConfigurationProperties(prefix = "fop.factory.pool")
public class MyClass {
    ...
}

From my - limited - understanding, @Primary is marking a MyClass as higher priority for being injected as a bean and @ConfigurationProperties is defining a prefix for accessing MyClass (e.g. via application.properties files and the like?). What's lost on me is how @ConfigurationProperties and @Primary working together is causing multiple bean definitions? How do I fix this? I retried with removing only the @Primary/@ConfigurationProperties but this caused runtime issues later on.

本文标签: javaMultiple bean definition error after updating to Spring Boot 34Stack Overflow