JBoss Community

injecting env-entry into interceptor by @Resource does not work

created by gunter zeilinger in EJB3 - View the full discussion

I use an Interceptor to initialize a POJO Service deployed as EJB Singleton:

 

public class LdapDicomConfigurationInterceptor {

 

    @Resource(name="ldapURL") String ldapURL;

    @Resource(name="userDN") String userDN;

    @Resource(name="password") String password;

    @Resource(name="baseDN") String baseDN;

 

    @PostConstruct

    void init(InvocationContext ctx) {

        LdapDicomConfiguration dc = (LdapDicomConfiguration) ctx.getTarget();

        LdapEnv env = new LdapEnv();

        env.setUrl(ldapURL);

        env.setUserDN(userDN);

        env.setPassword(password);

        try {

            dc.init(env, baseDN);

        } catch (Exception e) {

            throw new RuntimeException(e);

        }

    }

 

    @PreDestroy

    void close(InvocationContext ctx) {

        LdapDicomConfiguration dc = (LdapDicomConfiguration) ctx.getTarget();

        dc.close();

    }

}

 

ejb-jar.xml:

 

<ejb-jar

  xmlns="http://java.sun.com/xml/ns/javaee"

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"

  version="3.1">

  <enterprise-beans>

    <session>

      <ejb-name>DicomConfiguration</ejb-name>

      <ejb-class>org.dcm4che.conf.ldap.LdapDicomConfiguration</ejb-class>

      <session-type>Singleton</session-type>

      <init-on-startup>true</init-on-startup>

    </session>

  </enterprise-beans>

  <interceptors>

    <interceptor>

      <interceptor-class>org.dcm4chee.conf.ldap.LdapDicomConfigurationInterceptor</interceptor-class>

      <env-entry>

        <env-entry-name>ldapURL</env-entry-name>

        <env-entry-type>java.lang.String</env-entry-type>

        <env-entry-value>ldap://localhost:389</env-entry-value>

      </env-entry>

      <env-entry>

        <env-entry-name>userDN</env-entry-name>

        <env-entry-type>java.lang.String</env-entry-type>

        <env-entry-value>cn=admin,dc=nodomain</env-entry-value>

      </env-entry>

      <env-entry>

        <env-entry-name>password</env-entry-name>

        <env-entry-type>java.lang.String</env-entry-type>

        <env-entry-value>admin</env-entry-value>

      </env-entry>

      <env-entry>

        <env-entry-name>baseDN</env-entry-name>

        <env-entry-type>java.lang.String</env-entry-type>

        <env-entry-value>dc=nodomain</env-entry-value>

      </env-entry>

    </interceptor>

  </interceptors>

  <assembly-descriptor>

    <container-transaction>

      <method>

      <ejb-name>DicomConfiguration</ejb-name>

      <method-name>*</method-name>

      </method>

      <trans-attribute>NotSupported</trans-attribute>

    </container-transaction>

    <interceptor-binding>

      <ejb-name>DicomConfiguration</ejb-name>

      <interceptor-class>org.dcm4chee.conf.ldap.LdapDicomConfigurationInterceptor</interceptor-class>

    </interceptor-binding>

  </assembly-descriptor>

</ejb-jar>

 

But LdapDicomConfigurationInterceptor fields does not get injected.

 

Specifiying injection fields in ejb-jar.xml by

 

      <env-entry>

        <env-entry-name>password</env-entry-name>

        <env-entry-type>java.lang.String</env-entry-type>

        <env-entry-value>admin</env-entry-value>

        <injection-target>

          <injection-target-class>org.dcm4chee.conf.ldap.LdapDicomConfigurationInterceptor</injection-target-class>

          <injection-target-name>password</injection-target-name>

        </injection-target>

      </env-entry>

 

instead of @Resource works.

 

 

AS: jboss-as-7.1.1.Final

JAVA: OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode

OS: Linux amd64 3.3.7-1-ARCH

Reply to this message by going to Community

Start a new discussion in EJB3 at Community