Is it possible in Spring to autowire only specific arguments of a constructor?
I defined:
<bean class="MyClass">
<constructor-arg name="name" value="object name" />
</bean>
With:
public class MyClass{
private String name;
private MyDAO dao;
@Autowired
public MyClass(String name, MyDao dao){
// assign...
}
// ...
}
Now I’d like MyDao object to be autowired, while explicitly define name argument.
Is it possible?
Defining a bean using XML requires to manually define all arguments?
You cannot do that with the autowired constructor, because it affects all parameters, but you can do this:
It is similar to having a setter for the DAO but you don’t expose that public setter it in your class.