9.2.2.3. スキャンプロセスからの Bean の除外

概要

Weld の機能の 1 つである JBoss Enterprise Application Platform の CDI 実装は、スキャンからアーカイブのクラスを除外する機能であり、コンテナライフサイクルイベントを発生させ、Bean としてデプロイされます。これは、JSR-299 仕様の一部ではありません。

例9.1 Bean からのパッケージの除外

以下の例では、複数の <weld:exclude> タグが使用されています。
  1. 最初のタグでは、すべての Swing クラスが除外されます。
  2. 2 番目のタグでは、Google Web Toolkit がインストールされていない場合に Google Web Toolkit クラスが除外されます。
  3. 3 番目のタグでは、文字列 Blether (通常の式を使用) で終了するクラスが除外されます (システムプロパティー verbosity low に設定されている場合)。
  4. 4 番目のタグでは、Java Server Faces (JSF) クラスが除外されます (Wicket クラスが存在し、viewlayer システムプロパティーが設定されてない場合)。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:weld="http://jboss.org/schema/weld/beans" 
       xsi:schemaLocation="
          http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
          http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
    
    <weld:scan>
      
        <!-- Don't deploy the classes for the swing app! -->
        <weld:exclude name="com.acme.swing.**" />
      
        <!-- Don't include GWT support if GWT is not installed -->
        <weld:exclude name="com.acme.gwt.**">
            <weld:if-class-available name="!com.google.GWT"/>
        </weld:exclude>
        
        <!--
            Exclude classes which end in Blether if the system property verbosity is set to low
            i.e.
              java ... -Dverbosity=low            
        -->        
        <weld:exclude pattern="^(.*)Blether$">
            <weld:if-system-property name="verbosity" value="low"/>
        </weld:exclude>
        
       <!--
             Don't include JSF support if Wicket classes are present, and the viewlayer system
             property is not set
        -->
        <weld:exclude name="com.acme.jsf.**">
            <weld:if-class-available name="org.apache.wicket.Wicket"/>
            <weld:if-system-property name="!viewlayer"/>
        </weld:exclude>
    </weld:scan>
</beans>

Weld 固有の設定オプションの正式な仕様は http://jboss.org/schema/weld/beans_1_1.xsd で参照できます。