Sie*_*tse 8 java annotations jboss-mdb ejb-3.0
我正在尝试使用此方法在EJB3应用程序中接收邮件.简而言之,这意味着使用以下注释创建MDB:
@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...
}
}
Run Code Online (Sandbox Code Playgroud)
我有这个工作,但情况不太理想:主机名,用户名和密码是硬编码的.如果没有使用ant和build.properties在编译之前替换这些值,我不知道如何外化它们.
使用MBean是理想的,但我不知道如何从MBean获取值到MDB配置.
我该怎么做?
Bre*_*nah 13
您可以将注释外部化到您在jar文件的META-INF中部署的ejb-jar.xml,如下所示:
<?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>
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用-Dmdb.user.name = theUserName将mdb.user.name值设置为系统属性作为应用程序服务器命令行的一部分,它将被mdb神奇地拾取.
希望有所帮助.
归档时间: |
|
查看次数: |
12397 次 |
最近记录: |