2

These annotations are used in Spring to managed IoC. For every possible use of these, is there some case when we don't need to declare they because Spring already would detect Its use?

Is preferable to use @Inject than @Autowired because It is specified from Java and It's newer?

OneNoOne
  • 587
  • 7
  • 23
  • You need to declare them when you use Field injection. With Constructor injection you can not declare them – Lino May 21 '19 at 13:54
  • Please checkout the extensive discussion here https://stackoverflow.com/questions/7142622/what-is-the-difference-between-inject-and-autowired-in-spring-framework-which – kosgeinsky May 21 '19 at 13:55

1 Answers1

2

IMO such annotations should always be explicitly declared. Spring does not require it for constructor DI. However, I would avoid doing anything framework specific, unless it is required. That being said, I would use the javax Inject annotation and be explicit everywhere.

mre
  • 43,520
  • 33
  • 120
  • 170