users@jersey.java.net

Jersey Spring CONTEXT_CONFIG_LOCATION <was> Re: [Jersey] Problems using JerseyTest

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 06 Oct 2009 16:09:40 +0200

Hi,

I think this is a bug in the Jersey spring configuration and it should
also fail if using a web.xml. Is that your experience?

The problem is in the following method on the Jersey SpringServlet:

     private ConfigurableApplicationContext getChildContext(String
contextConfigLocation) {
         final ConfigurableWebApplicationContext ctx = new
XmlWebApplicationContext();
         ctx.setParent(getDefaultContext());
         ctx.setServletContext(getServletContext());
         ctx.setConfigLocations(new String[]
{contextConfigLocation}); // <-- Problem is here

         ctx.refresh();
         return ctx;
     }

It appears that the method call to:

   ctx.setConfigLocations(new String[]{contextConfigLocation});

http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/ConfigurableWebApplicationContext.html#setConfigLocations%28java.lang.String
[]%29

is wrong and it should be:

   ctx.setConfigLocation(contextConfigLocation);

i.e. the call with the array assumes only one location per element.

Could you log an issue?

Thanks,
Paul.

On Oct 6, 2009, at 3:53 PM, tarjei wrote:

> Hi,
>
> I'm trying to use the JerseyTest framework but I got a problem
> building the WebAppDescriptor.
>
> The code I call is:
> super(new WebAppDescriptor.Builder(
> "com.example.web"
> )
> .contextPath("/")
> //.contextParam("contextConfigLocation",
> "classpath:applicationContext.xml")
> .contextParam("contextConfigLocation",
> "classpath:applicationContext-HSQLdb.xml,
> classpath:applicationContext-service.xml,
> classpath:applicationContext-security.xml")
> /*
> .contextParam("contextConfigLocation",
> "classpath:applicationContext-resources.xml")
> .contextParam("contextConfigLocation",
> "classpath:applicationContext-service.xml")
> .contextParam("contextConfigLocation",
> "classpath:applicationContext-security.xml")
> .contextParam("contextConfigLocation",
> "classpath:applicationContext-tx.xml")
> */
> .servletClass(SpringServlet.class)
> .contextListenerClass(ContextLoaderListener.class)
> .build());
>
>
> And I get the error:
>
> Oct 6, 2009 3:40:42 PM
> com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
> INFO: Creating new child context from classpath:applicationContext-
> HSQLdb.xml, classpath:applicationContext-service.xml,
> classpath:applicationContext-security.xml
> 15:40:42.364 [http9998-WorkerThread(0)] INFO
> o.s.w.c.s.XmlWebApplicationContext - Refreshing org.springframework.web.context.support.XmlWebApplicationContext
> @1ed620: display name [Root WebApplicationContext]; startup date
> [Tue Oct 06 15:40:42 CEST 2009]; parent: org.springframework.web.context.support.XmlWebApplicationContext
> @df48c4
> 15:40:42.364 [http9998-WorkerThread(0)] INFO
> o.s.b.f.x.XmlBeanDefinitionReader - Loading XML bean definitions
> from class path resource [applicationContext-HSQLdb.xml,
> classpath:applicationContext-service.xml,
> classpath:applicationContext-security.xml]
> Oct 6, 2009 3:40:42 PM
> com.sun.jersey.spi.spring.container.servlet.SpringServlet initiate
> SEVERE: Exception occurred when intialization
> org.springframework.beans.factory.BeanDefinitionStoreException:
> IOException parsing XML document from class path resource
> [applicationContext-HSQLdb.xml, classpath:applicationContext-
> service.xml, classpath:applicationContext-security.xml]; nested
> exception is java.io.FileNotFoundException: class path resource
> [applicationContext-HSQLdb.xml, classpath:applicationContext-
> service.xml, classpath:applicationContext-security.xml] cannot be
> opened because it does not exist
> at
> org
> .springframework
> .beans
> .factory
> .xml
> .XmlBeanDefinitionReader
> .loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
> at
> org
> .springframework
> .beans
> .factory
> .xml
> .XmlBeanDefinitionReader
> .loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
> at
> org
> .springframework
> .beans
> .factory
> .support
> .AbstractBeanDefinitionReader
> .loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
> at
> org
> .springframework
> .beans
> .factory
> .support
> .AbstractBeanDefinitionReader
> .loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
> at
> org
> .springframework
> .beans
> .factory
> .support
> .AbstractBeanDefinitionReader
> .loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
> at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions
> (XmlWebApplicationContext.java:124)
> at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions
> (XmlWebApplicationContext.java:92)
> at
> org
> .springframework
> .context
> .support
> .AbstractRefreshableApplicationContext
> .refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
> at
> org
> .springframework
> .context
> .support
> .AbstractApplicationContext
> .obtainFreshBeanFactory(AbstractApplicationContext.java:422)
> at
> org
> .springframework
> .context
> .support
> .AbstractApplicationContext.refresh(AbstractApplicationContext.java:
> 352)
> at
> com
> .sun
> .jersey
> .spi
> .spring
> .container.servlet.SpringServlet.getChildContext(SpringServlet.java:
> 121)
> at
> com
> .sun
> .jersey
> .spi
> .spring
> .container.servlet.SpringServlet.getContext(SpringServlet.java:111)
> at
> com
> .sun
> .jersey
> .spi
> .spring.container.servlet.SpringServlet.initiate(SpringServlet.java:
> 97)
> at com.sun.jersey.spi.container.servlet.ServletContainer
> $InternalWebComponent.initiate(ServletContainer.java:242)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.load(WebComponent.java:466)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.init(WebComponent.java:182)
> at
> com
> .sun
> .jersey
> .spi.container.servlet.ServletContainer.init(ServletContainer.java:
> 281)
> at
> com
> .sun
> .jersey
> .spi.container.servlet.ServletContainer.init(ServletContainer.java:
> 442)
> at javax.servlet.GenericServlet.init(GenericServlet.java:241)
>
>
> What is the correct syntax to have multiple applicationContext
> files? I cannot use applicationContext* as I want a spesific
> configuration here.
>
> kind regards,
> Tarjei
>
> --
> Tarjei Huse
> Mobil: 920 63 413
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>