Announcement Announcement Module
Collapse
No announcement yet.
Include an extra bean when bulding for development Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Include an extra bean when bulding for development

    Hi!

    We want to include an extra bean in our applicationContext.xml when bulding our webapp for development. This bean contains some dummyusers for logging in without talking with ldap.

    We are using maven2 and spring 2.0.

    I have been playing around with profiles in maven but can't get this to do quite as I describe above.

    I would be thankful for any ideas on how to do this.

    TIA!


    -Kaj

  • #2
    If you are using wildcard patterns for loading configuration files you can just drop another one in the location when deploying in development. We used to do a similar thing to allow customers to register more beans.

    Comment


    • #3
      Originally posted by karldmoore View Post
      If you are using wildcard patterns for loading configuration files you can just drop another one in the location when deploying in development. We used to do a similar thing to allow customers to register more beans.
      Thanks for answering!

      Wildcards was the word which made me solve this issue

      I solved this by using profiles in maven to include/exclude files so the files I wanted was included and then I used wildcards in my web.xml like

      Code:
         <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                    /WEB-INF/applicationContext.xml 
                    /WEB-INF/classes/usersAndHosts*.xml
            </param-value>
         </context-param>

      Comment


      • #4
        I was I bit too fast here...

        This solution works fine when building a war which is deployed on resin, but does not work with "mvn jetty:run".

        The applicationContext does not pick up the bean.

        Code:
        DEBUG 08.09 19:17:36:58 (PathMatchingResourcePatternResolver.java:findPathMatchingResources:327) - Resolved location pattern [/WEB-INF/classes/usersAndHosts*.xml] to resources []
        DEBUG 08.09 19:17:36:59 (AbstractBeanDefinitionReader.java:loadBeanDefinitions:160) - Loaded 0 bean definitions from location pattern [/WEB-INF/classes/usersAndHosts*.xml]
        Back to the drawing board...


        -Kaj

        Comment


        • #5
          I solved this by letting the bean which got a bean injected looking for the bean in afterPropertiesSet instead of getting it injected. The xml file defining the bean it is looking for is either in the classpath or not, and the maven profile selected decide if this file should be inclued or not.

          My afterPropertiesSet looks like the following:

          Code:
              public void afterPropertiesSet() throws Exception {
                  Map matchingBeansAsMap = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.applicationContext,
                          UsersAndHostsForTesting.class, true, false);
                  List<UsersAndHostsForTesting> matchingBean = new ArrayList(matchingBeansAsMap.values());
                  if (matchingBean.size() > 0) {
                      usersAndHostsForTesting = matchingBean.get(0);
                      logger.info("Found a bean of class UsersAndHostsForTesting");
                  } else {
                      logger.info("Did not find a bean of class UsersAndHostsForTesting (which is a good thing when not running in development mode)");
                  }
              }
          Feel free to suggest any smarter solutions

          -Kaj

          Comment

          Working...
          X