Results 1 to 2 of 2

Thread: tilesconfigurer and junit

  1. #1
    Join Date
    Nov 2004
    Posts
    5

    Default tilesconfigurer and junit

    I am trying to run unit tests on my (hibernate) DAOs, but my tiles configurer keeps getting in the way.
    The error I'm getting is
    1) warning(junit.framework.TestSuite$1)junit.framewor k.AssertionFailedError: Exception in constructor: testSaveUser (org.springframework.beans.factory.BeanCreationExc eption: Error creating bean with name 'tilesConfigurer' defined in class path resource [WEB-INF/spring-config.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.tiles.TilesCo nfigurer@eac5a] does not run in a WebApplicationContext but in: org.springframework.context.support.ClassPathXmlAp plicationContext: displayName=[org.springframework.context.support.ClassPathXmlAp plicationContext;hashCode=15717714]; startup date=[Tue Nov 30 12:33:41 CST 2004]; root of ApplicationContext hierarchy
    java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.tiles.TilesCo nfigurer@eac5a] does not run in a WebApplicationContext but in: org.springframework.context.support.ClassPathXmlAp plicationContext: displayName=[org.springframework.context.support.ClassPathXmlAp plicationContext;hashCode=15717714]; startup date=[Tue Nov 30 12:33:41 CST 2004]; root of ApplicationContext hierarchy
    at org.springframework.web.context.support.WebApplica tionObjectSupport.getWebApplicationContext(WebAppl icationObjectSupport.java:42)
    ...

    What I figure is happening is the TilesConfigurer bean doesn't like being started without a tomcat (or other web container) instance. Can I get around this without having two different spring xml files? The app. runs fine if I start it as a webapp in tomcat.

    Thanks,
    James

  2. #2
    Join Date
    Nov 2004
    Posts
    5

    Default aha!

    So the simple solution is as follows (for anyone who is having this problem):

    1. put all non-tiles bean definitions in your main spring xml (usually applicationContext.xml, though I prefer spring-config.xml)

    2. put all tiles-specific bean definitions in a separate spring-tiles-beans.xml

    3. use both spring configs in the web.xml like:

    <!-- set the location of the spring config file for the listener below: -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/spring-config.xml
    /WEB-INF/spring-tiles-config.xml
    </param-value>
    </context-param>

    4. use only the main version in whatever test beans, like:
    String[] paths = {"/WEB-INF/spring-config.xml"};
    ApplicationContext ctx = new ClassPathXmlApplicationContext(paths);

    (I guess if you're a diehard XP fan, do the steps in the order 4-3-1-2 )

    -James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •