设置 metadata-complete="true" 后如何处理注释(解决了Tomcat 7启动缓慢的问题)? [英] What to do with annotations after setting metadata-complete="true" (which resolved slow Tomcat 7 start-up)?

查看:59
本文介绍了设置 metadata-complete="true" 后如何处理注释(解决了Tomcat 7启动缓慢的问题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎Tomcat 7 启动缓慢的问题可以通过在web.xml 中将metadata-complete"设置为true"来解决,如下所示:

Seems like the slow Tomcat 7 startup problem can be resolved with "metadata-complete" set to "true" in the web.xml, like so:

<?xml version="1.0" encoding="UTF-8"?>
<web-app metadata-complete="true" id="WebApp_ID" version="3.0"...

问题在于 Tomcat 在启动时扫描注解,这显着减慢了它的速度.我的时间从 25 秒减少到 5 秒.(更多信息请见:Tomcat 和 Servlet 3.0 Web 配置)

The problem is that Tomcat scans for annotations at startup, and this significantly slows it down. My time is cut down from 25 secs to 5 secs. (More info here: Tomcat and Servlet 3.0 Web Configuration)

但是,我的代码中有一些注释,例如:

However, I have some annotations in my code, like:

@ManagedBean
@RequestScoped
@Override
...

我很困惑 - 在我设置了 metadata-complete="true" 后,我的代码还能工作吗?我是否必须删除注释并将所有内容移动到 web.xml 中?

I am confused - will my code work after I have set metadata-complete="true"? Do I have to remove annotations and move everything into web.xml?

推荐答案

启动缓慢是因为/WEB-INF/lib中的每个JAR文件中的每个class文件也被扫描了Servlet 3.0 特定的注释.您显然在 /WEB-INF/lib 中有很多(大)JAR 文件.

The slow startup is caused because every single class file in every single JAR file in /WEB-INF/lib is also scanned for Servlet 3.0 specific annotations. You apparently have a lot of (large) JAR files in /WEB-INF/lib.

metadata-complete=true" 表示不需要扫描 /WEB-INF/lib 中的 JAR 文件以获取 Servlet 3.0 特定的注释,但仍会扫描 webapp 自己的类.

The metadata-complete="true" indicates that the JAR files in /WEB-INF/lib doesn't need to be scanned for Servlet 3.0 specific annotations, but the webapp's own classes will still be scanned.

请注意,您在此处列出了两个 JSF 注释和一个 Java SE 注释,而不是任何 Servlet 3.0 注释.Servlet 3.0 注释列在 javax.servlet.annotation 包.只有当 JAR 文件包含 JSF 2.0 兼容的 /META-INF/faces-config.xml 文件时,JSF 才会扫描注解.它不会立即扫描每个 JAR 文件中的每个类.Java SE @Override 注释不是运行时注释,而只是编译时的帮助.

Note that you listed there two JSF annotations and one Java SE annotation, not any Servlet 3.0 annotations. The Servlet 3.0 annotations are listed in the javax.servlet.annotation package. JSF will only scan for annotations when the JAR file contains a JSF 2.0 compatible /META-INF/faces-config.xml file. It won't immediately scan every single class in every JAR file. The Java SE @Override annotation is not a runtime annotation, but a compile-time aid only.

这篇关于设置 metadata-complete="true" 后如何处理注释(解决了Tomcat 7启动缓慢的问题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆