このコンテンツは選択した言語では利用できません。

7.4.4. Enable EJB and MDB Property Substitution in an Application


A new feature in Red Hat JBoss Enterprise Application Platform allows you to enable property substitution in EJBs and MDBs using the @ActivationConfigProperty and @Resource annotations. Property substitution requires the following configuration and code changes.
  • You must enable property substitution in the JBoss EAP server configuration file.
  • You must define the system properties in the server configuration file or pass them as arguments when you start the JBoss EAP server.
  • You must modify the code to use the substitution variables.

Procedure 7.7. Implement Property Substitution in an MDB Application

The following code examples are based on the helloworld-mdb quickstart that ships with JBoss EAP 6.3 or later. This topic shows you how to modify that quickstart to enable property substitution.
  1. Configure the JBoss EAP server to enable property substitution.

    The JBoss EAP server must be configured to enable property substitution. To do this, set the <annotation-property-replacement> attribute in the ee subsystem of the server configuration file to true.
    1. Back up the server configuration file. The helloworld-mdb quickstart example requires the full profile for a standalone server, so this is the standalone/configuration/standalone-full.xml file. If you are running your server in a managed domain, this is the domain/configuration/domain.xml file.
    2. Start the JBoss EAP server with the full profile.
      For Linux:
      EAP_HOME/bin/standalone.sh -c standalone-full.xml
      Copy to Clipboard Toggle word wrap
      For Windows:
      EAP_HOMEbin\standalone.bat -c standalone-full.xml
      Copy to Clipboard Toggle word wrap
    3. Launch the Management CLI using the command for your operating system.
      For Linux:
      EAP_HOME/bin/jboss-cli.sh --connect
      Copy to Clipboard Toggle word wrap
      For Windows:
      EAP_HOME\bin\jboss-cli.bat --connect
      Copy to Clipboard Toggle word wrap
    4. Type the following command to enable annotation property substitution.
      /subsystem=ee:write-attribute(name=annotation-property-replacement,value=true) 
      Copy to Clipboard Toggle word wrap
    5. You should see the following result:
      {"outcome" => "success"}
      Copy to Clipboard Toggle word wrap
    6. Review the changes to the JBoss EAP server configuration file. The ee subsystem should now contain the following XML.
      <subsystem xmlns="urn:jboss:domain:ee:1.2">
          <spec-descriptor-property-replacement>false</spec-descriptor-property-replacement>
          <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
          <annotation-property-replacement>true</annotation-property-replacement>
      </subsystem>
      Copy to Clipboard Toggle word wrap
  2. Define the system properties.

    You can specify the system properties in the server configuration file or you can pass them as command line arguments when you start the JBoss EAP server. System properties defined in the server configuration file take precedence over those passed on the command line when you start the server.
    • Define the system properties in the server configuration file.
      1. Start the JBoss EAP server and Management API as described in the previous step.
      2. Use the following command syntax to configure a system property in the JBoss EAP server:
        /system-property=PROPERTY_NAME:add(value=PROPERTY_VALUE) 
        Copy to Clipboard Toggle word wrap
        For the helloworld-mdb quickstart, we configure the following system properties:
        /system-property=property.helloworldmdb.queue:add(value=java:/queue/HELLOWORLDMDBPropQueue)
        /system-property=property.helloworldmdb.topic:add(value=java:/topic/HELLOWORLDMDBPropTopic)
        /system-property=property.connection.factory:add(value=java:/ConnectionFactory)
        Copy to Clipboard Toggle word wrap
      3. Review the changes to the JBoss EAP server configuration file. The following system properties should now appear in the after the <extensions>.
        <system-properties>
            <property name="property.helloworldmdb.queue" value="java:/queue/HELLOWORLDMDBPropQueue"/>
            <property name="property.helloworldmdb.topic" value="java:/topic/HELLOWORLDMDBPropTopic"/>
            <property name="property.connection.factory" value="java:/ConnectionFactory"/>
        </system-properties>
        Copy to Clipboard Toggle word wrap
    • Pass the system properties as arguments on the command line when you start the JBoss EAP server in the form of -DPROPERTY_NAME=PROPERTY_VALUE. The following is an example of how to pass the arguments for the system properties defined in the previous step.
      EAP_HOME/bin/standalone.sh -c standalone-full.xml -Dproperty.helloworldmdb.queuejava:/queue/HELLOWORLDMDBPropQueue -Dproperty.helloworldmdb.topic=java:/topic/HELLOWORLDMDBPropTopic -Dproperty.connection.factory=java:/ConnectionFactory
      Copy to Clipboard Toggle word wrap
  3. Modify the code to use the system property substitutions.

    Replace hard-coded @ActivationConfigProperty and @Resource annotation values with substitutions for the newly defined system properties. The following are examples of how to change the helloworld-mdb quickstart to use the newly defined system property substitutions within the annotations in the source code.
    1. Change the @ActivationConfigProperty destination property value in the HelloWorldQueueMDB class to use the substitution for the system property. The @MessageDriven annotation should now look like this:
      @MessageDriven(name = "HelloWorldQueueMDB", activationConfig = {
          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
          @ActivationConfigProperty(propertyName = "destination", propertyValue = "${property.helloworldmdb.queue}"),   
          @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
      
      Copy to Clipboard Toggle word wrap
    2. Change the @ActivationConfigProperty destination property value in the HelloWorldTopicMDB class to use the substitution for the system property. The @MessageDriven annotation should now look like this:
      @MessageDriven(name = "HelloWorldQTopicMDB", activationConfig = {
          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
          @ActivationConfigProperty(propertyName = "destination", propertyValue = "${property.helloworldmdb.topic}"),   
          @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
      Copy to Clipboard Toggle word wrap
    3. Change the @Resource annotations in the HelloWorldMDBServletClient class to use the system property substitutions. The code should now look like this:
      @Resource(mappedName = "${property.connection.factory}")
      private ConnectionFactory connectionFactory;
      
      @Resource(mappedName = "${property.helloworldmdb.queue}")   
      private Queue queue;
      
      @Resource(mappedName = "${property.helloworldmdb.topic}")
      private Topic topic;
      
      Copy to Clipboard Toggle word wrap
    4. Modify the hornetq-jms.xml file to use the system property substitution values.
      <?xml version="1.0" encoding="UTF-8"?>
      <messaging-deployment xmlns="urn:jboss:messaging-deployment:1.0">
          <hornetq-server>
              <jms-destinations>
                  <jms-queue name="HELLOWORLDMDBQueue">
                      <entry name="${property.helloworldmdb.queue}"/>
                  </jms-queue>
                  <jms-topic name="HELLOWORLDMDBTopic">
                      <entry name="${property.helloworldmdb.topic}"/>
                  </jms-topic>
              </jms-destinations>
          </hornetq-server>
      </messaging-deployment>
      Copy to Clipboard Toggle word wrap
  4. Deploy the application. The application will now use the values specified by the system properties for the @Resource and @ActivationConfigProperty property values.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat