Spring Component Scan (@Autowire) in signed Jar Files is slow

我的梦境 提交于 2019-12-05 18:52:13

I'm currently encountering the same problem with a signed uber-jar. It might not have something to do with auto-wiring but with context component scanning, in case you are using this in an XML configuration too. I've found an old Spring core ticket mentioning that. The ticket was closed with Resolution: Won't Fix though...

I have removed component scanning and replaced it with XML beans and it seems to be working. I still have problems with CXF web services generated at runtime using introspection (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean). Each service needs around 2 minutes to be created. But at least some progress was made.

Something else worth noting: the application is slow with Java Web Start on Java 9 although it's super fast with 1.8

The solution is to create a candidate component index using spring-context-indexer. Add the spring-context-indexer as a compileOnly dependency in Gradle or register it as an annotation processor in your IDE.

See the documentation.

This will create a file called spring.components in the META-INF directory of your jar. Spring will automatically use this list of components instead of scanning every class of the entire jar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!