Nice introduction to @Autowired in spring applications Posted in coding on 2016-06-23

When coming from plain java, one of the larger hurdles in understanding spring applications is how annotations are being used by spring to help developers to focus on business logic.

Every now and then, @Autowired is used in classes. When you boil it down, its very simple:

  • During startup of your spring application, the spring framework scans the classpath for classes that contain a @Component annotation or its children (e.g. @Service, @Controller, @Repository).
  • The classes it finds, are stored in a registry and then available for injection via @Autowired annotation
  • Everytime you use a @Autowired annotation, spring looks up the class in the registry and places an instance of that class where you defined it. Thats it.

baeldung.com has a nice summary about it, shedding some light on a few more usecases


Contact

  • Email
  • github
  • stackoverflow

Information

  • Env: production

Theme

  • krisawzm-blank-bootstrap
2016, .