4.6.3. 시스템 속성 대체를 사용하도록 애플리케이션 코드 수정

하드 코딩된 @ActivationConfigProperty@Resource 주석 값을 새로 정의된 시스템 속성의 대체로 바꿉니다. 다음은 새로 정의된 시스템 속성 대체를 사용하도록 helloworld-mdb 빠른 시작을 변경하는 방법의 예입니다.

  1. 시스템 속성에 대체를 사용하도록 HelloWorldQueueMDB 클래스에서 @ActivationConfigProperty 대상 속성 값을 변경합니다. 이제 @MessageDriven 주석이 다음과 같이 표시됩니다.

    HelloWorldQueueMDB 코드 예

    @MessageDriven(name = "HelloWorldQueueMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "${property.helloworldmdb.queue}"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

  2. 시스템 속성에 대체를 사용하도록 HelloWorldTopicMDB 클래스에서 @ActivationConfigProperty 대상 속성 값을 변경합니다. 이제 @MessageDriven 주석이 다음과 같이 표시됩니다.

    HelloWorldTopicMDB Code Example

    @MessageDriven(name = "HelloWorldQTopicMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "${property.helloworldmdb.topic}"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

  3. 시스템 속성 대체를 사용하도록 HelloWorldMDBServletClient 클래스에서 @Resource 주석을 변경합니다. 이제 코드는 다음과 같아야 합니다.

    HelloWorldMDBServletClient 코드 예

    /**
     * Definition of the two Jakarta Messaging Service destinations used by the quickstart
     * (one queue and one topic).
     */
     @JMSDestinationDefinitions(
         value = {
             @JMSDestinationDefinition(
                 name = "java:/${property.helloworldmdb.queue}",
                 interfaceName = "javax.jms.Queue",
                 destinationName = "HelloWorldMDBQueue"
             ),
             @JMSDestinationDefinition(
                 name = "java:/${property.helloworldmdb.topic}",
                 interfaceName = "javax.jms.Topic",
                 destinationName = "HelloWorldMDBTopic"
             )
         })
    /**
     * <p>
     * A simple servlet 3 as client that sends several messages to a queue or a topic.
     * </p>
     *
     * <p>
     * The servlet is registered and mapped to /HelloWorldMDBServletClient using the {@linkplain WebServlet
     * @HttpServlet}.
     * </p>
     *
     * @author Serge Pagop (spagop@redhat.com)
     *
     */
    @WebServlet("/HelloWorldMDBServletClient")
    public class HelloWorldMDBServletClient extends HttpServlet {
    
        private static final long serialVersionUID = -8314035702649252239L;
    
        private static final int MSG_COUNT = 5;
    
        @Inject
        private JMSContext context;
    
        @Resource(lookup = "${property.helloworldmdb.queue}")
        private Queue queue;
    
        @Resource(lookup = "${property.helloworldmdb.topic}")
        private Topic topic;
    
      <!-- Remainder of code can be found in the `helloworld-mdb-propertysubstitution` quickstart. -->

  4. 시스템 속성 대체 값을 사용하도록 the activemq-jms.xml 파일을 수정합니다.

    예: .activemq-jms.xml 파일

    <?xml version="1.0" encoding="UTF-8"?>
    <messaging-deployment xmlns="urn:jboss:messaging-activemq-deployment:1.0">
        <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>
        </server>
    </messaging-deployment>

  5. 애플리케이션을 배포합니다. 애플리케이션에서 @Resource 및 @ ActivationConfigProperty 속성 값에 대해 시스템 속성에 지정된 값을 사용합니다.