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

factory-method - improve error message when method is not static [SPR-6837] #11503

Closed
spring-projects-issues opened this issue Feb 14, 2010 · 0 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Michael Isvy opened SPR-6837 and commented

I'm using the following configuration:

<bean class="factory.ClientServiceSingleton" id="clientServiceSingleton" factory-method="getInstance"/>
public class ClientServiceSingleton {
	
	private static ClientServiceSingleton instance = new ClientServiceSingleton();
	
	private ClientServiceSingleton() {}	
	public ClientServiceSingleton getInstance() {
		return instance;
	}

}

As you might have noticed, I have omitted declaring the getInstance method as static.
In that case, the error message is as follows:

Error creating bean with name 'clientServiceSingleton' defined in class path resource [factory/method/factorymethod-config.xml]: 
No matching factory method found: factory method 'getInstance'

Also, STS is not showing an explicit message either.

I believe the error message could show something such as:

No matching factory method found: factory method 'getInstance'. Check that the method exists and that it is static.

note: in case the return type is incorrect, it crashes far after, when injecting the dependency. So at this stage, the error message should not mention that the return type might be wrong.


Referenced from: commits 18bd4a8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants