Tomcat 扫描注释太慢

Ser*_*Ten 5 java tomcat annotations dcevm

我有一个 Tomcat 8.5.32 配置为使用 DCEVM

\n\n
JAVA_OPTS="-Xms512m -Dcatalina.home=$CATALINA_HOME -XXaltjvm=dcevm -javaagent:/usr/share/tomcat/lib/hotswap-agent-1.3.0.jar=autoHotswap=true"\n
Run Code Online (Sandbox Code Playgroud)\n\n

要动态重新加载的类在 $CATALINA_HOME/conf/Catalina/localhost/mycontext.xml 中指定,以便 Tomcat 直接从 Eclipse 自动重新生成的 .class 文件重新加载它们。

\n\n
<Context docBase="~/workspace/myapp/myapp-web/src/main/webapp">\n<Resources>\n    <PostResources className="org.apache.catalina.webresources.DirResourceSet"\n                   base="/vagrant/workspace/myapp/myapp-models/target/classes" internalPath="/" webAppMount="/WEB-INF/classes" />\n    <PostResources className="org.apache.catalina.webresources.DirResourceSet"\n                   base="/vagrant/workspace/myapp/myapp-services/target/classes" internalPath="/" webAppMount="/WEB-INF/classes" />\n    <PostResources className="org.apache.catalina.webresources.DirResourceSet"\n                   base="/vagrant/workspace/clocial/myapp-web/target/classes" internalPath="/" webAppMount="/WEB-INF/classes" />\n    <PostResources className="org.apache.catalina.webresources.DirResourceSet"\n                   base="/vagrant/workspace/myapp/myapp-web/target/lib" internalPath="/" webAppMount="/WEB-INF/lib" />\n  </Resources>\n</Context>\n
Run Code Online (Sandbox Code Playgroud)\n\n

这可行,但 Tomcat 加载上下文需要两分钟多的时间,因为有一百多个目录。

\n\n

通过org.apache.catalina.startup.ContextConfig.level = FINE在 conf/logging.properties 进行设置,我得到了一条跟踪信息,表明大部分时间大概都花在了搜索注释上。

\n\n

有没有办法告诉 Tomcat 不要在某些目录中查找注释,以便只扫描实际包含带注释的类的目录?

\n\n

我\xc2\xb4一直在阅读ContextConfig 的源代码,似乎有一些排除规则,但我无法\xc2\xb4理解它们。

\n\n

以下是 catalina.out 的摘录:

\n\n
12:39:32.992 INFO org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor [/usr/share/tomcat/conf/Catalina/localhost/mycontext.xml]\n12:39:33.092 FINE org.apache.catalina.startup.ContextConfig.init ContextConfig: Initializing\n12:39:33.093 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Processing context [/clocial] configuration file [file:/usr/share/tomcat/conf/context.xml]\n12:39:33.123 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Successfully processed context [/clocial] configuration file [file:/usr/share/tomcat/conf/context.xml]\n12:39:33.123 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Processing context [/clocial] configuration file [file:/usr/share/tomcat/conf/Catalina/localhost/mycontext.xml]\n12:39:33.140 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Successfully processed context [/clocial] configuration file [file:/usr/share/tomcat/conf/Catalina/localhost/mycontext.xml]\n12:39:47.640 FINE org.apache.catalina.startup.ContextConfig.configureStart ContextConfig: Processing START\n12:39:47.641 FINE org.apache.catalina.startup.ContextConfig.configureStart Context [/clocial] will parse web.xml and web-fragment.xml files with validation:[false] and namespaceAware:[false]\n12:39:58.524 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Scanning web application directory for class files with annotations [file:/vagrant/workspace/myapp/myapp-models/target/classes/com/]\n12:40:00.594 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Scanning web application directory for class files with annotations [file:/vagrant/workspace/myapp/myapp-models/target/classes/com/mypackage/]\n12:40:00.768 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Scanning web application directory for class files with annotations [file:/vagrant/workspace/myapp/myapp-models/target/classes/com/mypackage/blob/]\n12:40:00.867 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Scanning web application directory for class files with annotations [file:/vagrant/workspace/myapp/myapp-models/target/classes/com/mypackage/blob/tables/]\n12:40:00.968 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Scanning web application directory for class files with annotations [file:/vagrant/workspace/myapp/myapp-models/target/classes/com/mypackage/blob/test/]\n...\nanother hundred directories\n...\n12:41:07.051 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource Scanning web application directory for class files with annotations [file:/vagrant/workspace/myapp/myapp-web/target/classes/com/mypackage/mymodel/]\n12:41:07.104 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsFile Scanning directory for class files with annotations [/usr/share/tomcat/lib]\n12:41:07.142 FINE org.apache.catalina.startup.ContextConfig.authenticatorConfig Configured an authenticator for method [NONE]\n
Run Code Online (Sandbox Code Playgroud)\n