0

Take the following as an example

 public class xyz(){
    @Autowired
    private BasicConfiguration configuration;

    @RequestMapping("/dynamic-configuration")
    public Map dynamicConfiguration() {
        // Not the best practice to use a map to store differnt types!
        Map map = new HashMap();
        map.put("message", configuration.getMessage());
        map.put("number", configuration.getNumber());
        map.put("key", configuration.isValue());
        return map;
    }
}

Every documentation i read says that it injects dependecies, however i dont understand what that means. As far as i understand, Spring creates a JavaBean of the class xyz and a javabean is a basically a standard for classes. If so, what use has the@autowire here?. Doesn't xyz have the same object "configuration" whether I annotate it or not?.

NicO
  • 591
  • 2
  • 8
  • 21
  • No, it doesnt. It has a member field that by default points to null, meaning you have no instance of ``BasicConfiguration`` to work with. Dependency Injection provides you with an instance. – f1sh Nov 23 '18 at 13:40
  • Another possible duplicate: [Understanding Spring @Autowired usage](https://stackoverflow.com/q/19414734/476716) – OrangeDog Nov 23 '18 at 13:41

0 Answers0