配置值MDB注解 [英] Configurable values to MDB annotations

查看:115
本文介绍了配置值MDB注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用这种方法在我们EJB3接收邮件应用程序。总之,这意味着与以下注释创建一个MDB:

I'm trying to use this method for receiving mail in our EJB3 app. In short, that means creating an MDB with the following annotations:

@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "mailServer", propertyValue = "imap.company.com"),
    @ActivationConfigProperty(propertyName = "mailFolder", propertyValue = "INBOX"),
    @ActivationConfigProperty(propertyName = "storeProtocol", propertyValue = "imap"),
    @ActivationConfigProperty(propertyName = "debug", propertyValue = "false"),
    @ActivationConfigProperty(propertyName = "userName", propertyValue = "username"),
    @ActivationConfigProperty(propertyName = "password", propertyValue = "pass") })
@ResourceAdapter("mail-ra.rar")
@Name("mailMessageBean")
public class MailMessageBean implements MailListener {
    public void onMessage(final Message msg) {
       ...snip...
    }
}

我有这个工作,但情况不太理想:主机名,用户名和密码是硬codeD。短期使用Ant和build.properties更换编译之前这些价值观,我不知道如何来具体化它们。

I have this working, but the situation is less than ideal: The hostname, username and password are hardcoded. Short of using ant and build.properties to replace those values before compilation, I don't know how to externalize them.

这将是理想的使用一个MBean,但我不知道怎么去从MBean值的MDB配置。

It would be ideal to use an MBean, but I have no idea how to get the values from the MBean to the MDB configuration.

我应该怎么做呢?

推荐答案

您可以外化注释到您在您的jar文件的META-INF部署ejb-jar.xml中,如下所示:

You can externalise the annotations into the ejb-jar.xml that you deploy in the META-INF of your jar file as follows:

<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar version="3.0">
    <enterprise-beans>
    	<message-driven>
            <ejb-name>YourMDB</ejb-name>
            <ejb-class>MailMessageBean</ejb-class>        
    		<activation-config>
    			<activation-config-property>
    			   <activation-config-property-name>username</activation-config-property-name>
    			   <activation-config-property-value>${mdb.user.name}</activation-config-property-value>
    			</activation-config-property>
...
...
            </activation-config>
        </message-driven>
    </enterprise-beans>

然后就可以设置mdb.user.name值作为系统属性作为使用命令行到应用服务器的一部分-Dmdb.user.name = theUserName,它会神奇地得到由MDB回升。

Then you can set the mdb.user.name value as a system property as part of the command line to your application server using -Dmdb.user.name=theUserName and it will magically get picked up by the mdb.

希望有所帮助。

这篇关于配置值MDB注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆