سؤال

وأنا أحاول أن استخدام هذه الطريقة للحصول على تلقي البريد في 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...
    }
}

ولدي هذا العمل، ولكن الوضع هو أقل من مثالية: اسم المضيف، اسم المستخدم وكلمة المرور ضمني. باختصار استخدام النمل وbuild.properties لتحل محل تلك القيم قبل تجميع، وأنا لا أعرف كيف لتخريج لهم.

وسيكون مثاليا لاستخدام MBean، ولكن ليس لدي أي فكرة عن كيفية الحصول على القيم من MBean إلى تكوين MDB.

وكيف أفعل هذا؟

هل كانت مفيدة؟

المحلول

ويمكنك externalise شروح في المنظمة بتبني-jar.xml أن نشر في META-INF الملف جرة على النحو التالي:

<?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.

وعلى أمل أن يساعد.

نصائح أخرى

واعتبارا من جبوس AS 5.1 على الأقل، يمكنك استخدام اوب لتكوينActivationConfigProperties. لقد اكتشفت هذا من خلال النظر في الأمثلة التي جبوس يوفر <لأ href = "http://docs.jboss.org/ejb3/docs/tutorial/1.0.0/ejb3-1.0.0-tutorials.zip" يختلط = "نوفولو "> هنا . وهذا مفيد إذا كنت لا تريد اسم المستخدم وكلمات السر متاحة للحاوية كاملة في خاصية النظم، أو إذا كنت مثلي، وأبدا، وأكرر NEVER، ترغب في نشر قطعة أثرية مع اسم المستخدم / كلمة السر في ذلك. أي كيف، وهنا هو جيست ...

وعلق على MDB مثل هذا ...

...
@MessageDriven
@AspectDomain("TestMDBean")
public class TestMDBean implements MessageListener {
...

وثم إضافة $ {مهما} -aop.xml إلى دير نشر مع الداخلية مثل أدناه. تركت التعليقات الأصلي في هناك في حالة Jaikiran لا تجعل التغييرات المذكورة ...

<اقتباس فقرة>   

ملحوظة: يجب أن يكون الشرح على واحد   خط فقط.

<?xml version="1.0" encoding="UTF-8"?>
<aop xmlns="urn:jboss:aop-beans:1.0">
   <!-- TODO: Jaikiran - These interceptor declarations need not be here since they 
   are already declared through the ejb3-interceptors-aop.xml. Duplicating them leads to
   deployment errors. However, if this custom-ejb3-interceptors-aop.xml needs to be 
   independent, then we must find a better way of declaring these. Right now, commenting these
   out, can be looked at later. -->
   <!--    
   <interceptor class="org.jboss.ejb3.AllowedOperationsInterceptor" scope="PER_VM"/>
   <interceptor class="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor" scope="PER_VM"/>
   <interceptor factory="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" scope="PER_CLASS"/>
   <interceptor class="org.jboss.ejb3.stateless.StatelessInstanceInterceptor" scope="PER_VM"/>

   <interceptor factory="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory" scope="PER_CLASS_JOINPOINT"/>
   <interceptor factory="org.jboss.aspects.tx.TxInterceptorFactory" scope="PER_CLASS_JOINPOINT"/>
   -->
   <domain name="TestMDBean" extends="Message Driven Bean" inheritBindings="true">
      <annotation expr="!class(@org.jboss.ejb3.annotation.DefaultActivationSpecs)">
         @org.jboss.ejb3.annotation.DefaultActivationSpecs (value={@javax.ejb.ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @javax.ejb.ActivationConfigProperty(propertyName="destination", propertyValue="queue/MyQueue"), @javax.ejb.ActivationConfigProperty(propertyName="user", propertyValue="testusr"), @javax.ejb.ActivationConfigProperty(propertyName="password", propertyValue="testpwd")})
      </annotation>
   </domain>
</aop>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top