Different Spring Annotation XML Declarations

后端 未结 2 1686
孤独总比滥情好
孤独总比滥情好 2021-01-14 00:37

There seem to be multiple XML tags for telling Spring to use annotations:





        
2条回答
  •  感动是毒
    2021-01-14 01:21

    I would think tags 1 and 2 could be combined into one. So I don't know why they are separated.

    For reasons of backwards compatibility. Old Spring apps have to keep working, and merging the tags (which were introduced in different versions of Spring) would break that by changing the default behaviour.

    Tags 3 and 4 seem redundant to 1 and 2.

    See above. The 4 tags do slightly different, but complimentary things. Yes, if Spring were designed from scratch, there would be fewer of them, but the functionality needs to remain seperate.

    To summarise:

    enables annotation support in the context. This was added as part of Java 5 support, at a time when Spring still supported Java 1.4

    enables automatic scanning and configuration of beans, instead of using explicit declarations. This was added in Spring 2.5.

    is an odd one. It is not required in order to support annotated controller (those work by default). What it does is to actually disable the old style of non-annotated controller, as well as adding support for things like JSON. This is required because older apps still use the older controller style.

    is required because Spring supports many different styles of transaction demarcation, one of which is the annotation style. This is most popular style, but by no means the only one.

提交回复
热议问题