Performance difference between spring javaconfig, xml config and annotations

前端 未结 4 562
天命终不由人
天命终不由人 2021-01-12 10:50

Our Spring configuration contains about 1200 beans, and we use component-scan/@Autowired. If we exported the ApplicationContext as an Xml (and still used @Autowired), we sav

相关标签:
4条回答
  • 2021-01-12 11:27

    I did a naive benchmark using XML, annotation, and Java config. The results were surprising (Java config was slower). I have no idea whether this would be relevant in your situation, benchmarks being what they are...

    http://www.jroller.com/kenwdelong/entry/is_spring_javaconfig_faster

    0 讨论(0)
  • 2021-01-12 11:27

    I would guess a bit less, because no parsing will have ho happen (the annotations are 'parsed' with reflection, the xml - with an xml parser).

    That, however, should not be a reason to choose one configuration option over the other. Startup time is not important for performance.

    0 讨论(0)
  • 2021-01-12 11:30

    I actually tried this a while back and depressingly it was not faster.. or at least not perceivable faster. In some cases when I actually measured it was slower (ever so slightly). I wish I had numbers but it was one of those quick tests for my own benefit. I also didn't have 1200 beans but about 200.

    I also noticed mixing XML and Java config gave the worst performance (ever so slightly).

    What I have found to be the bottleneck in my Spring bootup time is Hibernate. I'm doing another project with much of the same config w/o Hibernate using JDBC and the bootup time is about 1/3.

    0 讨论(0)
  • 2021-01-12 11:35

    The difference is likely not between annotations and XML, but instead it'll be the startup performance hit of using component-scanning, which is slow. If you add component-scanning to your XML version, you should find that it's just as slow.

    0 讨论(0)
提交回复
热议问题