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

BeanCreationException error message should always include declaring class of constructor (or factory method) #27139

Closed
schauder opened this issue Jul 7, 2021 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@schauder
Copy link
Contributor

schauder commented Jul 7, 2021

While working on Spring Data support for Spring Native I see error messages coming from
https://github.com/spring-projects/spring-framework/blob/main/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java#L279
I get exceptions like the one below.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchAuditingHandler': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1354) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[na:na]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[na:na]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[na:na]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[data-elasticsearch:2.5.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[data-elasticsearch:2.5.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[data-elasticsearch:2.5.2]
	at com.example.data.elasticsearch.ElasticsearchApplication.main(ElasticsearchApplication.java:33) ~[data-elasticsearch:0.0.1-SNAPSHOT]

Unfortunately it does not contain information about the class to be constructed, which would be really helpful when trying to get things in Spring Native to work.

I think this happens when we construct BeanDefinitions programmatically, but I’m not completely sure about that.

It would be great if the error message could be improved to always include the class name to be constructed.

@jhoeller jhoeller self-assigned this Jul 7, 2021
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Jul 7, 2021
@jhoeller jhoeller added this to the 5.3.9 milestone Jul 7, 2021
@jhoeller jhoeller changed the title Error message of BeanCreationException should always contain the class name of the bean to be constructed. BeanCreationException error message should always include declaring class of constructor (or factory method) Jul 7, 2021
@jhoeller jhoeller added the for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x label Jul 7, 2021
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x labels Jul 7, 2021
jhoeller added a commit that referenced this issue Jul 13, 2021
Zoran0104 pushed a commit to Zoran0104/spring-framework that referenced this issue Aug 20, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants