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
版权声明:本文标题:java - Multiple bean definition error after updating to Spring Boot 3.4 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743936068a2564702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论