4.6.3. 修改应用程序代码以使用系统属性替代
将硬编码的 @ActivationConfigProperty
和 @Resource
注释值替换为新定义的系统属性。以下是如何更改 helloworld-mdb
quickstart 以使用新定义的系统属性替换的示例:
更改
HelloWorldQueueMDB
类中的@ActivationConfigProperty
destination
属性值,以使用 system 属性替换。@MessageDriven
注释现在应如下所示:HelloWorldQueueMDB Code Example
@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "${property.helloworldmdb.queue}"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "${property.helloworldmdb.queue}"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 更改
HelloWorldTopicMDB
类中的@ActivationConfigProperty
目标
属性值,以使用 system 属性替换。@MessageDriven
注释现在应如下所示:HelloWorldTopicMDB 代码示例
@MessageDriven(name = "HelloWorldQTopicMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "${property.helloworldmdb.topic}"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
@MessageDriven(name = "HelloWorldQTopicMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "${property.helloworldmdb.topic}"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 更改
HelloWorldMDBServletClient
类中的@Resource
注释,以使用系统属性替换。现在,代码应该类似如下:HelloWorldMDBServletClient Code Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 修改
activemq-jms.xml
文件,以使用系统属性替换值。.activemq-jms.xml 文件示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
部署应用。应用现在将系统属性指定的值用于
@Resource 和 @
ActivationConfigProperty
属性值。