The following examples are for injecting the string from and XML and a Java-based configuration:
XML
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="MyTaskConstructor" class="java.lang.String"> <constructor-arg type="char[]" value="My value"></constructor-arg> </bean> <bean id="myTask" class="com.package.MyTask"> <constructor-arg ref="MyTaskConstructor"/> </bean> </beans> Java-based
@Configuration public class MyTaskConfig { @Bean public String getMyTaskConstructor() { return "My value"; } @Bean public MyTask myTask() { return new MyTask(getMyTaskConstructor()); } }