It's good to use @Autowired for a method with any number of arguments. The only problem is that the application context should be able to determine what you want to enter for each of these arguments.
The complaint in the error message makes this very clear: you do not have a unique String bean defined in the context of your application.
The solution for your specific example would be to use the @Value annotation for each of the arguments:
@Autowired set(@Value("${user.name:anonymous}") String name, @Value("${user.age:30}") int age)
This will allow you to use the PropertyPlaceholderConfigurer defined in your context to resolve these properties and revert to the provided default values if these properties are not defined.
If you want to introduce objects that are defined as beans in your context, you only need to make sure that for each argument you need only one bean match:
@Autowired set(SomeUniqueService myService, @Qualifier("aParticularBean") SomeBean someBean)
The above example assumes that in the application context there is only one instance of SomeUniqueService , but there can be several instances of SomeBean , however only one of them will have a bean id "aParticularBean".
As a final note, this use case for @Autowired most suitable for constructors, as it rarely happens when you need to set properties as massive once an object has been created.
Edit:
I noticed your XML configuration after writing the answer; it is completely useless. If you want to use annotations, just define a bean without any properties and make sure you declare <context:annotation-config/> somewhere in your context:
<context:annotation-config/> <bean id="myBean" class="com.spring.examples.MyBean"/>
Thus, the container will detect everything that needs to be entered and act accordingly. The XML element <property/> can only be used to call java bean sets (which take only one argument).
Alternatively, you can annotate your class with a stereotype like @Component (or @Service or something else), and then just use <context:component-scan/> ; this eliminates the need to declare each individual bean in XML.