-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Condition evaluation on beans with similar factory methods are mixed #30688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Parameter 0 of method xxx required a bean of type xxx that could not be found.
Parameter 0 of method xxx required a bean of type xxx that could not be found.
Parameter 0 of method xxx required a bean of type xxx that could not be found.
This isn't allowed in Java regardless of what the The |
As highlighted by @mdeinum, this is not a valid code snippet. @wang-xiaowu Please provide a minimal sample application that reproduces this issue. |
plz look this demo |
I am not sure how it's related to
As a result, the bean is not created at all. If I specify a bean name this still fails which is a bit strange. |
Parameter 0 of method xxx required a bean of type xxx that could not be found.
Here is refined test case: package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import com.example.demo.ApplicationTests.Config.UserBean;
@SpringBootTest
public class ApplicationTests {
@Autowired
private ApplicationContext ctx;
@Test
void test() {
ctx.getBean(UserBean.class);
}
@Configuration(enforceUniqueMethods = false)
static class Config {
@Bean
@ConditionalOnProperty(value = "sync", havingValue = "true", matchIfMissing = true)
UserBean user(Environment env) {
return new UserBean.User1();
}
@Bean
@ConditionalOnProperty(value = "sync", havingValue = "false")
UserBean user() {
return new UserBean.User2();
}
@Bean
String pet() {
return "pet";
}
public static class UserBean {
static class User1 extends UserBean {
}
static class User2 extends UserBean {
}
}
}
} plugins {
id "java"
id "org.springframework.boot" version "3.1.0"
id "io.spring.dependency-management" version "1.1.0"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
sourceCompatibility = "17"
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.named("test") {
useJUnitPlatform()
}
Although the |
is there a deadline or version for this problem to be revoled? |
I am afraid there isn't. I would argue that there is nothing blocking you really as using the same method name is not recommended. You could refactor your code to have dedicated method names (as they should) and that would allow you to move forward. |
yes,that is what i am doing |
We intend to deprecate the use of overloaded It's not just condition declarations, it's any kind of metadata that looks like it is specific to the declared method while in reality it is part of a bean definition that potentially delegates to several factory methods. Distinct bean definitions with distinct metadata need to have distinct bean names, otherwise it is a semantic mess and also a mess in terms of readability. |
Affects: SpringBoot 3.1.0
i am using
@Configuration(enforceUniqueMethods = false)
to allow the configuration has the save name of beans, but if i setsync: false
,it show the errorParameter 0 of method xxx required a bean of type xxx that could not be found.
.it only execute the code which is on the top, for example i put the
SyncFlatMessageHandlerImpl
bean on the top ofAsyncFlatMessageHandlerImpl
and setsync: true
,it also show the errorParameter 0 of method xxx required a bean of type xxx that could not be found.
. because it did not execute the code inAsyncFlatMessageHandlerImpl
The text was updated successfully, but these errors were encountered: