Inspectopedia Help

Incorrect constructor injection in XML Spring bean

Reports Spring <bean> using constructor-based dependency injection.

The inspection triggers when it can't find an appropriate constructor or factory method for <bean> with the configured <constructor-arg> tags and defined autowire policy.


public class MyComponent { // constructor public MyComponent(MyBean bean) {} // factory method public static MyComponent getInstance(String name, int port) { }
<beans> <bean class="beans.MyComponent" id="foo"> <!-- reports "No matching constructor found in class 'MyComponent" --> <constructor-arg ref="myBean"/> <constructor-arg value="123"/> </bean> <bean class="beans.MyComponent" factory-method="getInstance"> <!-- reports "No matching factory method found in class" --> <constructor-arg value="123"/> </bean> </beans>

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Spring, 241.16690

Last modified: 29 April 2024