Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions