I have WAR package with CDI beans. Deployment of the package is very slow because every time during deployment the package is scanned for CDI beans. Is there any option to disable this process?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The correct way is to disable discovery in the beans.xml of the relevant archive:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="none">
</beans>
According to the CDI specification this removes the archive from the list of bean-archives.
回答2:
I have a feeling that what you're looking for is more of a tool. As mentioned, Weld uses class scanning to find annotations. There are ways to speed this up. One that works pretty well is Jandex, an annotation processor that can be used at compile time to create an index (easier to read database) of your classes and annotations. This does dramatically boost deployment times.