Announcement Announcement Module
Collapse
No announcement yet.
Where to put beans.xml in JBoss Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where to put beans.xml in JBoss

    Where do I put the beans.xml where it will be found?

    ClassPathResource res = new ClassPathResource("beans.xml");

    Doesn't seem to be able to find it. I've tried putting it in conf, in the WEB-INF/classes directory, in the lib directory jarred up. I was hoping with the global classloader this might be simple.

    Am I going to have to do the applicationContext? I was hoping to do it sort of globally so more than one web app can use the same Spring context. I was just hoping to do it the minimal way for now until I learn Spring better.

    Thanks,
    Steve

  • #2
    You can add the contextLoaderListener to your web.xml, such as:

    Code:
    <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    Then you only need to specify the applicationContext file location as a context-param (also in web.xml), such as:

    Code:
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/beans.xml</param-value>
    </context-param>
    At startup, this will create a WebApplicationContext which is then stored in the ServletContext. To access it you can use a static convenience method:

    Code:
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    To read more: http://static.springframework.org/sp...tegration.html

    Comment


    • #3
      What about Cactus tests?

      Do I have to use the WebApplicationContext? I mean, does my ServletTestCase need to know about the context, or will it automatically wire my setUserSession() up automatically?

      I would assume that Cactus isn't smart enough to do that, so I need to actually create an instantiation of UserSession programmatically.

      Thanks,
      Steve

      Comment


      • #4
        Steve,

        You might want to have a look at the spring-mock.jar classes for testing the web framework which provides mock objects for request, response, session, etc. These will allow for dependency-injection in test code and do not require running tests within the application server.

        Comment

        Working...
        X