Tomcat слишком медленно сканирует аннотации - PullRequest
0 голосов
/ 18 октября 2018

У меня есть Tomcat 8.5.32, настроенный для использования DCEVM с

JAVA_OPTS="-Xms512m -Dcatalina.home=$CATALINA_HOME -XXaltjvm=dcevm -javaagent:/usr/share/tomcat/lib/hotswap-agent-1.3.0.jar=autoHotswap=true"

Классы для динамической перезагрузки указаны в $ CATALINA_HOME / conf / Catalina / localhost / mycontext.xml, чтобы Tomcat перезагружал ихнепосредственно из файлов .class, автоматически сгенерированных Eclipse.

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

Это работает, но Tomcat загружает контекст более чем за две минуты, поскольку существует более ста каталогов.

Установкойorg.apache.catalina.startup.ContextConfig.level = FINE в conf / logging.properties Я получил след, говорящий о том, что большую часть времени якобы тратится на поиск аннотаций.

Есть ли способ сообщить Tomcat, что он не должен искать аннотации в определенных каталогахтак что сканируются только те, которые на самом деле содержат классы с аннотациями?

Я читал исходный код ContextConfig , и, похоже, существуют некоторые правила исключения, но яне могу их понять.

Вот выдержка из catalina.out:

12:39:32.992 INFO org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor [/usr/share/tomcat/conf/Catalina/localhost/mycontext.xml]
12:39:33.092 FINE org.apache.catalina.startup.ContextConfig.init ContextConfig: Initializing
12:39:33.093 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Processing context [/clocial] configuration file [file:/usr/share/tomcat/conf/context.xml]
12:39:33.123 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Successfully processed context [/clocial] configuration file [file:/usr/share/tomcat/conf/context.xml]
12:39:33.123 FINE org.apache.catalina.startup.ContextConfig.processContextConfig Processing context [/clocial] configuration file [file:/usr/share/tomcat/conf/Catalina/localhost/mycontext.xml]
12: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]
12:39:47.640 FINE org.apache.catalina.startup.ContextConfig.configureStart ContextConfig: Processing START
12: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]
12: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/]
12: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/]
12: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/]
12: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/]
12: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/]
...
another hundred directories
...
12: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/]
12:41:07.104 FINE org.apache.catalina.startup.ContextConfig.processAnnotationsFile Scanning directory for class files with annotations [/usr/share/tomcat/lib]
12:41:07.142 FINE org.apache.catalina.startup.ContextConfig.authenticatorConfig Configured an authenticator for method [NONE]
...