Correctness10 - SpotBugsExtensionForSpringFrameWork/CS5098 GitHub Wiki

Bug pattern name: NotWritablePropertyException

Description

Yet another possiblity is defining a bean – BeanA – with a reference to another bean – BeanB – without having the corresponding setter method in BeanA:

@Component
public class BeanA {
    private IBeanB dependency; // No setter created even though IBeanB is used here    
...
}
@Component
public class BeanB implements IBeanB { ... }
================================================================
<bean id="beanA" class="com.baeldung.web.BeanA">
    <property name="beanB" ref="beanB" />
</bean>

Solution

================================================================
@Component
public class BeanA {
    private IBeanB dependency;

    public void setDependency(final IBeanB dependency) { // add setter
        this.dependency = dependency;
    }
}

Reference List

baeldung

⚠️ **GitHub.com Fallback** ⚠️