- Building Applications with Spring 5 and Vue.js 2
- James J. Ye
- 93字
- 2025-04-04 16:05:52
Field-based injection
With the @Autowired annotation, you can apply it directly to a field. In this way, you don't need to declare a setter method for it, as in the following:
@Autowired
private MessageRepository repository;
Other annotations: Besides the built-in annotations, @Required and @Autowired, Spring also supports the @javax.annotation.Resource annotation specified in JSR-250 and the @javax.inject.Inject annotation from JSR-330.
Java Specification Request ( JSR): JSR 250 is for common annotations for the Java TM platform. JSR 330 is about dependency injection for Java. You can find more details at: https://jcp.org/en/jsr/detail?id=250 and https://jcp.org/en/jsr/detail?id=330.