Disable scanning of CDI beans in WAR

2019-07-10 05:21发布

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?

2条回答
ゆ 、 Hurt°
2楼-- · 2019-07-10 05:26

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.

查看更多
看我几分像从前
3楼-- · 2019-07-10 05:53

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.

查看更多
登录 后发表回答