I’m writing a note about @Value annotation‘s behaviour, whose description I haven’t found in the javadoc: when this annotation is applied to method’s parameters, it is required to apply @Autowired to the method itself, otherwise Spring’s autowiring doesn’t take place.

The following code snippet could be an example:

@Component
public class Example {
  @Autowired
  public void setParams(
      @Value("${param1}") String param1,
      @Value("${param2}") String param2)
  {
    // do something
  }
}

Tested with:

  • Java 6
  • Spring 4.1
Annunci