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>
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
SpringBeanConstructorArgInspection- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Spring, 243.23126 |
Last modified: 03 December 2024