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

Spring can't find lower visibility constructor if a public default constructor exits [SPR-7453] #12111

Closed
spring-projects-issues opened this issue Aug 11, 2010 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Sajid Insaf opened SPR-7453 and commented

Spring appears to be unable to find constructors with arguments and access modifier less than public when default public constructor is present.

Consider the class:

package test;
public SimpleBean {
public SimpleBean() {}
private SimpleBean(String x) {}
}

Context configuration:
<bean id="simpleBean" class="test.SimpleBean">
<constructor-arg value="test" />
</bean>

Spring throws the following exception:

org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'simpleBean' defined in class path resource [test/Test-context.xml]: 1 constructor arguments specified but no matching constructor found in bean 'simpleBean' (hint: specify index and/or type arguments for simple parameters to avoid type ambiguities)

Everything works fine (no exceptions) if

  1. The public default constructor is removed or its signature is changed to accept some argument.
  2. The access modifier of the zero argument constructor is anything less than public.

Affects: 2.5.6

Reference URL: http://forum.springsource.org/showthread.php?t=93609

Referenced from: commits 8a23ce9

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point, we should consistently find non-public multi-arg constructors there, even if public constructors with fewer or no arguments are declared in the same bean class. Fixed for 3.0.4.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.4 milestone Jan 11, 2019
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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants