Skip to content
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

Stronger warning about overridden bean in case of type mismatch [SPR-16125] #20673

Closed
spring-projects-issues opened this issue Oct 27, 2017 · 3 comments
Labels
in: core

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 27, 2017

Nguyen The Viet opened SPR-16125 and commented

I have following classes

package com.company1

class A {
}
package com.company2

class A {
}

class B {
  A a;
  B(A a) { this.a = a; }
}

with configurations

import com.company1.*;

class Config1 {
  @Bean A a() { return new A(); };
}

import com.company2.*;

class Config2 {
  @Bean A a() { return new A(); };
  @Bean B b(A a) { return new B(a) };
}

Expected: A warning or error about duplicated bean ids
Actual: Very ambiguous error - Parameter 0 of method b in com.company.Config2 required a bean of type 'com.company2.A' that could not be found.


Affects: 4.3.11

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 28, 2017

Juergen Hoeller commented

This seems like an unfortunate case of bean definition overriding where the overriding bean is of a different type than the overridden one, replacing it by name (as per the rules) but not providing a bean reference of the same type, leading to a bean-by-type-not found exception in code which still expects the original bean to be present.

In regular scenarios, an info-level log message "Overriding bean definition for bean..." should be issued. Could you please double-check whether that's present in your scenario? In any case, such overriding for a mix of standalone beans and @Bean-defined beans within configuration classes can be a bit tricky. Let's try to improve this as far as possible, at least providing clearer guidance in case of a type mismatch.

@spring-projects-issues spring-projects-issues added status: waiting-for-feedback type: enhancement in: core labels Jan 11, 2019
@rstoyanchev rstoyanchev removed status: waiting-for-triage type: enhancement labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 24, 2019

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder label Jan 24, 2019
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 25, 2019

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback status: feedback-reminder labels Jan 25, 2019
@snicoll snicoll removed this from the General Backlog milestone Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core
Projects
None yet
Development

No branches or pull requests

3 participants