Spring startup performance issues

前端 未结 6 711
春和景丽
春和景丽 2020-12-07 15:34

I\'m trying to integrate Spring in a pretty large application with thousands of classes, and i\'m experiencing huge delays starting my container because of component-scannin

6条回答
  •  再見小時候
    2020-12-07 16:37

    Question: How many (in %) of the classes in the directories are Spring Beans?

    Answer: I'm not really sure (it's a really big project) , but from what i saw i believe it's arround 90 to 100%, since xml and properties files are isolated in separate locations)

    If the problem is really the component scan and not the bean initializing process itself (and I highly doubt that), then the only solution I can imagine is to use Spring XML configuration instead of component scan. - (May you can create the XML file automatically).

    But if you have many classes and 90% - 100% of them are Beans, then, the reduction of scanned files will have a maximal improvement of 10%-0%.

    You should try other ways to speed up your initialization, may using lazy loading or any lazy loading related techniques, or (and that is not a joke) use faster hardware (if it is not a stand alone application).


    A easy way to generate the Spring XML is to write a simple spring application that uses the class path scanning like your original application. After all Beans are initialize, it iterates through the Beans in the Spring Context, check if the bean belongs to the important package and write the XML Config for this bean in a file.

提交回复
热议问题