As with everything else do a profiling and find out where you're really spending the time. Yes, Spring auto-detection can be slow in large applications but so can be eager initialization. Without profiling information you're just guessing what the problem is.
使用 Spring 4/Hibernate 4/Tomcat 7 和速度适中的笔记本电脑,您应该能够在 15 秒内启动。
Late to the game on an answer, but it if helps anyone: best thing I've found is go through your web.xml item by item and remove whatever bloat you can. This shaved off minutes for me. Profiling is also good as it can help you pinpoint expensive things like extra Hibernate session factories. Keep a lean POM to reduce classpath scanning time (use dependency tree). Using @Autowired is really handy, but if feasible and you have the time, go through your application and remove any unused references and unnecessary annotations. Same goes for component scanning. Make sure your DB connector is up to date. Much of the excessive startup time is often related to your specific application rather than modern Tomcat instances or the frameworks. If your application is huge and you can modularize them into different jars, you can simply load just the ones you need in dev for the task at the time.
Set your logging to WARN on noisy loggers. Adding TLD jars to skip in org.apache.catalina.startup.TldConfig.jarsToSkip in Tomcat 6/7 can also help. Native compile with APR didn't save startup time for me, though I'd imagine that helps a running container serving pages more than startup time. Also, disabling antiJARLocking/antiResourceLocking will speed up your Tomcat boot time.
You should be able to hit under a 15-second startup with Spring 4/Hibernate 4/Tomcat 7 and a moderately fast laptop.
发布评论
评论(2)
与其他所有事情一样,进行分析并找出您真正将时间花在哪里。是的,Spring 自动检测在大型应用程序中可能很慢,但急切的初始化也可能很慢。如果没有分析信息,您只能猜测问题所在。
As with everything else do a profiling and find out where you're really spending the time. Yes, Spring auto-detection can be slow in large applications but so can be eager initialization. Without profiling information you're just guessing what the problem is.
答案迟到了,但它对任何人都有帮助:我发现的最好的事情是逐项检查你的 web.xml 并删除你可以的任何膨胀。这为我节省了时间。分析也很好,因为它可以帮助您查明昂贵的东西,例如额外的 Hibernate 会话工厂。保持精简的 POM 以减少类路径扫描时间(使用依赖树)。使用 @Autowired 确实很方便,但如果可行并且您有时间,请检查您的应用程序并删除任何未使用的引用和不必要的注释。组件扫描也是如此。确保您的数据库连接器是最新的。大部分过多的启动时间通常与您的特定应用程序有关,而不是与现代 Tomcat 实例或框架有关。如果您的应用程序很大并且您可以将它们模块化到不同的 jar 中,那么您可以简单地在 dev 中加载当时任务所需的那些。
将日志记录设置为对嘈杂的记录器发出警告。在 Tomcat 6/7 的 org.apache.catalina.startup.TldConfig.jarsToSkip 中添加要跳过的 TLD jar 也会有所帮助。使用 APR 进行本机编译并没有为我节省启动时间,尽管我认为这对正在运行的容器提供页面服务比启动时间更有帮助。此外,禁用 antiJARLocking/antiResourceLocking 将加快 Tomcat 的启动时间。
使用 Spring 4/Hibernate 4/Tomcat 7 和速度适中的笔记本电脑,您应该能够在 15 秒内启动。
Late to the game on an answer, but it if helps anyone: best thing I've found is go through your web.xml item by item and remove whatever bloat you can. This shaved off minutes for me. Profiling is also good as it can help you pinpoint expensive things like extra Hibernate session factories. Keep a lean POM to reduce classpath scanning time (use dependency tree). Using @Autowired is really handy, but if feasible and you have the time, go through your application and remove any unused references and unnecessary annotations. Same goes for component scanning. Make sure your DB connector is up to date. Much of the excessive startup time is often related to your specific application rather than modern Tomcat instances or the frameworks. If your application is huge and you can modularize them into different jars, you can simply load just the ones you need in dev for the task at the time.
Set your logging to WARN on noisy loggers. Adding TLD jars to skip in org.apache.catalina.startup.TldConfig.jarsToSkip in Tomcat 6/7 can also help. Native compile with APR didn't save startup time for me, though I'd imagine that helps a running container serving pages more than startup time. Also, disabling antiJARLocking/antiResourceLocking will speed up your Tomcat boot time.
You should be able to hit under a 15-second startup with Spring 4/Hibernate 4/Tomcat 7 and a moderately fast laptop.