The role of annotations in spring

Annotation configuration has many advantages over XML configuration:

  • It can make full use of Java's reflection mechanism to obtain class structure information, which can effectively reduce the configuration work. For example, when using JPA annotations to configure ORM mapping, we do not need to specify the PO's attribute name, type and other information. If the relational table fields and PO attribute names and types are the same, you don't even need to write task attribute mapping information - because these information are all It can be obtained through the Java reflection mechanism.
  • Comments and Java code are in one file, while XML configuration uses a separate configuration file. Most configuration information will not be adjusted after the program is developed. If the configuration information and Java code are put together, it will help to enhance the cohesion of the program sex. With an independent XML configuration file, programmers often need to keep switching between program files and configuration files when writing a function. This kind of incoherence in thinking will reduce development efficiency.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326611167&siteId=291194637