Hello,
I'm learning Spring from the 3.1 spring_tutorial.PDF, and in @Autowired on Properties section we can read
I've understood that it works without the setter method, then I've tried
without/with setter method, but always throws an exception
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
If I use the @Autowired(required=false), the msg property is injected if it's defined in the xml, and I have no exception if I comment it, but only with the setter method.
When I comment the setter method I obtain
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'msg' of bean class [BeanTest]: Bean property 'msg' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
It only works with defined bean objects but not with
String? Why it works with required=false? It's needed the setter method?
I'm wrong or it is an issue?
Thanks.