The best way to inject String into your class is declare properties configurer in your Spring XML: something like this:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:/cfg/yourPropsFile.properties</value>
</list>
</property>
</bean>
If you are using annotations make sure that you have these lines in your spring file:
<context:annotation-config/>
<context:component-scan base-package="com.your.app"/>
Then just add that string you want to be injected in your spring bean into that file, for e.g.:
my.prop=Johnson
Then inject it in your controller using @Value annotation:
@Value("${my.prop}")
private String lastName;
This is assuming that your value needs to be configurable.
Otherwise if you need to inject String value as you are trying to do now, please note that by default using @Configurable annotation autowiring won't work. To enable autowiring you need to enable it using: @Configurable(autowire = Autowire.BY_NAME)
, but it shouldn't be used unless you really need it. @Configurable annotation is mostly used with AspecJ, which is not what you are trying to achieve here.
So define your class with @Component and using:
@Autowired
@Qualifier("lastName")
private String lastName;
will solve your problem.