I wonder why the following bean definition works in Spring DI (I use a bean instance with the static factory method and Guava Suppliers.ofInstance
):
<bean id="keySupplier" class="com.google.common.base.Suppliers" factory-method="ofInstance"> <constructor-arg> <value type="java.lang.String">someReallyLongValue </value> </constructor-arg> </bean>
but this is not:
<bean id="keySupplier" class="com.google.common.base.Suppliers" factory-method="ofInstance"> <constructor-arg type="java.lang.String" value="someReallyLongValue" /> </bean>
It throws the following exception:
org.springframework.beans.factory.BeanCreationException: an error occurred while creating a bean with the name userRepo defined in the class path resource:
(...)
Invalid dependency expressed in constructor argument with index 0 of type [java.lang.Object]:
Ambiguous argument types of the factory method - did you specify the correct bean references as arguments to the factory method?
The problem is in my case, when I use the first definition of a bean with a really long line as a value, my editor breaks the line after the last character of the line, which causes the line to be passed with extra spaces to Suppliers.ofInstance
and as a result it breaks my code.
The second definition will be more stringent with respect to spaces, but, oddly enough, it does not work (it probably does not cope with the generic type, despite the fact that the type is specified in the type attribute).
Can I make Spring ignore spaces in the <value>
tag somehow?
Or am I using <constructor-arg type="java.lang.String" value="someReallyLongValue" />
? Or should I point out the problem because it is a Spring bug?
I would prefer not to make any assumptions about the string (i.e. use string.trim()
here).
source share