Announcement Announcement Module
Collapse
No announcement yet.
Activate Spring profile for a MDB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Activate Spring profile for a MDB

    Hello.

    I'm using Spring profile for my webapp's and it works great.

    I activate those profile in web.xml files like this :

    Code:
     <context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>myProfile</param-value>
      </context-param>
    But I'm stuck with my MDB.

    I bootstrap spring from my MDB with the SpringBeanAutowiringInterceptor and it works but I don't known how to activate my profile for this MDB.

    I've tried to add an env-entry but it doesn't seem to work :

    Code:
    <env-entry>
            <env-entry-name>spring.profiles.active</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>myProfile</env-entry-value>
          </env-entry>
    Can someone help me?

    Is there a way to activate profile via the beanRefContext.xml (used by the interceptor) ?

    Thank you

    Stéphane

  • #2
    I've found a workaround with EJB Interceptors :

    Code:
    public class ActivateSpringProfileInterceptor {
    @Resource(name = "spring.profiles.active")
        private String springProfile;
    
        @PostConstruct
        @PostActivate
        public void activateProfile(InvocationContext ctx) throws Exception {
            if (springProfile == null || springProfile.isEmpty()) {
                throw new EJBException("No spring.profiles.active env-entry is found in DD for this EJB !");
            }
    
            System.setProperty("spring.profiles.active", springProfile);
    
            try {
                ctx.proceed();
            }
       }
    }
    and I put this in my ejb-jar.xml

    Code:
    <interceptors>
        <interceptor>
          <interceptor-class>ActivateSpringProfileInterceptor</interceptor-class>
          <env-entry>
            <env-entry-name>spring.profiles.active</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>${spring.profiles.active}</env-entry-value>
          </env-entry>
        </interceptor>
      </interceptors>
    It works but I would prefer not changing System variables...

    Any other workaround?

    Comment


    • #3
      Does anyone have a workaround? The problem with the system variable solution is that there is possible conflict if 2 applications run on the same virtual machine...

      Thanks !

      Comment

      Working...
      X