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.
Example:
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 | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Spring, 233.SNAPSHOT |
Last modified: 13 July 2023