Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Can't change contextConfigLocation

  1. #1
    Join Date
    Feb 2008
    Location
    Cambridge
    Posts
    10

    Default Can't change contextConfigLocation

    Hi,
    I'm trying to change the location of the applicationContext.xml file, or even the name of it, and pointing to it from the web.xml using contextConfigLocation, but I keep getting the same error: It first tries to read beans for the web application from the file I point to (/WEB-INF/context/applicationContext.xml) and then for each portlet it tries to read from the portlet's own context (eg /WEB-INF/basic-portlet.xml) and also the default location (/WEB-INF/applicationContext.xml)... which it obviously can't find as it's not there... which gives me a FileNotFoundException and portlet death... what I can't figure out is why it's looking there when it has clearly read the web.xml that points to a different location... thoughts?

    Logs:
    Code:
    [#|2009-01-29T17:49:35.950+0000|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=Timer-9;|PWC1412: WebModule[/WebServer] ServletContext.log():Initializing Spring root WebApplicationContext|#]
    
    [#|2009-01-29T17:49:35.950+0000|INFO|sun-appserver9.1|org.springframework.web.context.ContextLoader|_ThreadID=18;_ThreadName=Timer-9;|Root WebApplicationContext: initialization started|#]
    
    [#|2009-01-29T17:49:35.981+0000|INFO|sun-appserver9.1|org.springframework.web.context.support.XmlWebApplicationContext|_ThreadID=18;_ThreadName=Timer-9;|Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1506d68: display name [Root WebApplicationContext]; startup date [Thu Jan 29 17:49:35 GMT 2009]; root of context hierarchy|#]
    
    [#|2009-01-29T17:49:36.044+0000|INFO|sun-appserver9.1|org.springframework.beans.factory.xml.XmlBeanDefinitionReader|_ThreadID=18;_ThreadName=Timer-9;|Loading XML bean definitions from ServletContext resource [/WEB-INF/context/applicationContext.xml]|#]
    
    [#|2009-01-29T17:49:36.356+0000|INFO|sun-appserver9.1|org.springframework.web.context.support.XmlWebApplicationContext|_ThreadID=18;_ThreadName=Timer-9;|Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1506d68]: org.springframework.beans.factory.support.DefaultListableBeanFactory@197e73f|#]
    
    [#|2009-01-29T17:49:36.747+0000|INFO|sun-appserver9.1|org.springframework.beans.factory.support.DefaultListableBeanFactory|_ThreadID=18;_ThreadName=Timer-9;|Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@197e73f: defining beans [viewResolver]; root of factory hierarchy|#]
    
    [#|2009-01-29T17:49:36.794+0000|INFO|sun-appserver9.1|org.springframework.web.context.ContextLoader|_ThreadID=18;_ThreadName=Timer-9;|Root WebApplicationContext: initialization completed in 844 ms|#]
    
    [#|2009-01-29T17:49:36.794+0000|INFO|sun-appserver9.1|debug.com.sun.portal.portletcontainer.appengine.impl|_ThreadID=18;_ThreadName=Timer-9;WebServer;|PSPL_PAECSPPAI0015 : Loading DD for the portlet application : WebServer|#]
    
    [#|2009-01-29T17:49:36.794+0000|INFO|sun-appserver9.1|debug.com.sun.portal.portletcontainer.appengine.impl|_ThreadID=18;_ThreadName=Timer-9;Basic;|PSPL_PAECSPPAI0012 : Portlet Initialized: Basic|#]
    
    [#|2009-01-29T17:49:36.981+0000|INFO|sun-appserver9.1|org.springframework.web.portlet.DispatcherPortlet|_ThreadID=18;_ThreadName=Timer-9;|Initializing portlet 'Spring'|#]
    
    [#|2009-01-29T17:49:36.981+0000|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=18;_ThreadName=Timer-9;|PWC1412: WebModule[/WebServer] ServletContext.log():Initializing Spring FrameworkPortlet 'Spring'|#]
    
    [#|2009-01-29T17:49:36.981+0000|INFO|sun-appserver9.1|debug.com.sun.portal.portletcontainer.WebServer|_ThreadID=18;_ThreadName=Timer-9;|Initializing Spring FrameworkPortlet 'Spring'|#]
    
    [#|2009-01-29T17:49:36.997+0000|INFO|sun-appserver9.1|org.springframework.web.portlet.DispatcherPortlet|_ThreadID=18;_ThreadName=Timer-9;|FrameworkPortlet 'Spring': initialization started|#]
    
    [#|2009-01-29T17:49:36.997+0000|INFO|sun-appserver9.1|org.springframework.web.portlet.context.XmlPortletApplicationContext|_ThreadID=18;_ThreadName=Timer-9;|Refreshing org.springframework.web.portlet.context.XmlPortletApplicationContext@962202: display name [PortletApplicationContext for namespace 'Spring-portlet']; startup date [Thu Jan 29 17:49:36 GMT 2009]; parent: org.springframework.web.context.support.XmlWebApplicationContext@1506d68|#]
    
    [#|2009-01-29T17:49:36.997+0000|INFO|sun-appserver9.1|org.springframework.beans.factory.xml.XmlBeanDefinitionReader|_ThreadID=18;_ThreadName=Timer-9;|Loading XML bean definitions from PortletContext resource [/WEB-INF/Spring-portlet.xml]|#]
    
    [#|2009-01-29T17:49:37.013+0000|INFO|sun-appserver9.1|org.springframework.beans.factory.xml.XmlBeanDefinitionReader|_ThreadID=18;_ThreadName=Timer-9;|Loading XML bean definitions from PortletContext resource [/WEB-INF/applicationContext.xml]|#]
    
    [#|2009-01-29T17:49:37.013+0000|SEVERE|sun-appserver9.1|org.springframework.web.portlet.DispatcherPortlet|_ThreadID=18;_ThreadName=Timer-9;_RequestID=ef413f5d-8576-4139-b75d-870f600d4ab6;|Context initialization failed
    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from PortletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open PortletContext resource [/WEB-INF/applicationContext.xml]
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:284)
    	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.portlet.context.XmlPortletApplicationContext.loadBeanDefinitions(XmlPortletApplicationContext.java:124)
    	at org.springframework.web.portlet.context.XmlPortletApplicationContext.loadBeanDefinitions(XmlPortletApplicationContext.java:92)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:125)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:420)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:350)
    	at org.springframework.web.portlet.FrameworkPortlet.createPortletApplicationContext(FrameworkPortlet.java:347)
    	at org.springframework.web.portlet.FrameworkPortlet.initPortletApplicationContext(FrameworkPortlet.java:292)
    	at org.springframework.web.portlet.FrameworkPortlet.initPortletBean(FrameworkPortlet.java:265)
    	at org.springframework.web.portlet.GenericPortletBean.init(GenericPortletBean.java:116)
    	at javax.portlet.GenericPortlet.init(GenericPortlet.java:107)
    	at com.sun.portal.portletcontainer.appengine.impl.LifecycleManagerImpl.createPortlets(LifecycleManagerImpl.java:353)
    	at com.sun.portal.portletcontainer.appengine.impl.LifecycleManagerImpl.<init>(LifecycleManagerImpl.java:137)
    	...
    <more logs available if needed>
    Last edited by blaise17; Jan 30th, 2009 at 07:53 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    When posting code/xml/stacktraces please use [ code][/code ] tags...

    I suggest you read the web chapter and what the FrameworkPortlet actually does and how everything works together.

    Setting the context param 'contextConfigLocation' will only set the location used by the ContextLoaderListener, it is ignored by everything else. Each Servlet/Portlet loads its own configuration and by default it looks for something which is named [portletname]-portlet.xml or the default (applicationContext.xml). If you want to override this set the contextConfigLocation for each portlet/servlet (as an init-param to those).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2008
    Location
    Cambridge
    Posts
    10

    Default

    Okay, I'll post it in code tags in future, I just didn't as it clearly isn't code.

    "Each Servlet/Portlet loads its own configuration and by default it looks for something which is named [portletname]-portlet.xml or the default (applicationContext.xml)."
    But the portlet's configuration IS IN [portletname]-portlet.xml... nothing I've read (and I have read that chapter) says that it should look in BOTH if it finds the bean in the first.

    Additionally, in that chapter it says it will look in the portlet's default context or the root application context, which in this case is the one that has been changed...

    Does this mean that if I want to change the root application context I have to then set contextConfigLocation in EVERY portlet to be their own default and the changed location of the root one? In which case what is the point of setting it in the web.xml?
    Last edited by blaise17; Jan 30th, 2009 at 07:55 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Additionally, in that chapter it says it will look in the portlet's default context or the root application context, which in this case is the one that has been changed...
    It looks for BEANS in the root context it doesn't look at the context-param named contextConfigLocation.

    The root one is loaded by the ContextLoaderListener, all the Portlets/Servlets automatically detect this ApplicationContext and use that as the parent ApplicationContext for the ApplicationContext created by the Portlet.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Feb 2008
    Location
    Cambridge
    Posts
    10

    Default

    That is exactly what I'm asking about!

    The root one being loaded for everything is the one that has the changed location, which it is reading...
    But then, it also tries reading a root one in the default location for the root one, which isn't there because I've specified the root one to be moved...

    The only bean in the root context is a view resolver... the other beans for each portlet are in their own [portlet-name]-portlet.xml files... what exactly are you trying to say? That I've put the contextConfigLocation param in there? Because I haven't... that's not where it goes...

    I've specified it in the web.xml... but you can specify the portlet one's individuallly in the portlet.xml... which is what I was asking if that was what I had to do since it's ignoring that the one specified in the web.xml is the root for the portlets...

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    I'm probably stupid but you now totally lost me. Please post your configuration (web.xml/portlet.xml)...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Feb 2008
    Location
    Cambridge
    Posts
    10

    Default

    This is my web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
        <display-name>Portlet 2.0 Portlet Filter Sample</display-name>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/context/applicationContext.xml</param-value>
        </context-param>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        
        <servlet>
            <servlet-name>ViewRendererServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
        </servlet>
    
        <servlet>
            <servlet-name>ViewRendererServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>ViewRendererServlet</servlet-name>
            <url-pattern>/WEB-INF/servlet/view</url-pattern>
        </servlet-mapping>
        
    </web-app>
    I can post my portlet.xml as well if you like, but I'm not currently setting anything special in there... do you want me to?

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Please do and the exact version of spring you are using could be helpful also.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    Feb 2008
    Location
    Cambridge
    Posts
    10

    Default

    Here is my portlet.xml, I am using spring 3.0.0 milestone 1 :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" 
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                 xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" 
                 id="myPortletApp" version="2.0">
        
        <portlet>
            <description>A Basic Portlet</description>
            <portlet-name>Basic</portlet-name>
            <display-name>Basic Portlet</display-name>
            <portlet-class>portlets.BasicPortlet</portlet-class>
            <expiration-cache>0</expiration-cache>
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>VIEW</portlet-mode>
                <portlet-mode>HELP</portlet-mode>
                <portlet-mode>EDIT</portlet-mode>
            </supports>
            <portlet-info>
                <title>Basic Portlet</title>
                <short-title>Basic</short-title>
            </portlet-info>
        </portlet>
    
        <portlet>
            <description>A Spring Portlet</description>
            <portlet-name>Spring</portlet-name>
            <display-name>Spring Portlet</display-name>
            <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
            <init-param>
                <name>contextConfigLocation</name>
                <value>/WEB-INF/Spring-portlet.xml,/WEB-INF/applicationContext.xml</value>
            </init-param>
            <expiration-cache>0</expiration-cache>
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>VIEW</portlet-mode>
                <portlet-mode>HELP</portlet-mode>
                <portlet-mode>EDIT</portlet-mode>
            </supports>
            <portlet-info>
                <title>Spring Portlet</title>
                <short-title>Spring</short-title>
            </portlet-info>
        </portlet>
    
        <portlet>
            <description>A Basic Spring Portlet</description>
            <portlet-name>BasicSpring</portlet-name>
            <display-name>Basic Spring Portlet</display-name>
            <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
            <init-param>
                <name>contextConfigLocation</name>
                <value>/WEB-INF/BasicSpring-portlet.xml,/WEB-INF/applicationContext.xml</value>
            </init-param>
            <expiration-cache>0</expiration-cache>
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>VIEW</portlet-mode>
            </supports>
            <portlet-info>
                <title>Basic Spring Portlet</title>
                <short-title>BasicSpring</short-title>
            </portlet-info>
        </portlet>
    
        <portlet>
            <description>A Wrapped Portlet</description>
            <portlet-name>helloworld</portlet-name>
            <display-name>Wrapped Portlet</display-name>
            <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
            <expiration-cache>0</expiration-cache>
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>VIEW</portlet-mode>
                <portlet-mode>HELP</portlet-mode>
                <portlet-mode>EDIT</portlet-mode>
            </supports>
            <portlet-info>
                <title>Wrapped Portlet</title>
                <short-title>Wrapped</short-title>
            </portlet-info>
        </portlet>
    
    </portlet-app>

  10. #10
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Well you tell the portlet to load Spring-portlet.xml AND /WEB-INF/applicationContext.xml. Which isn't there so it doesn't load. Also WHY should it load the /WEB-INF/applicationContext.xml (which probably should be /WEB-INF/context/applicationContext).

    If you only have a Spring-portlet.xml to load you can remove the init-param. It will automatically detect the ApplicationContext loaded by the ContextLoaderListener...

    Code:
    <portlet>
        <description>A Spring Portlet</description>
        <portlet-name>Spring</portlet-name>
        <display-name>Spring Portlet</display-name>
        <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
        <init-param>
            <name>contextConfigLocation</name>
            <value>/WEB-INF/Spring-portlet.xml,/WEB-INF/applicationContext.xml</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
            <portlet-mode>HELP</portlet-mode>
            <portlet-mode>EDIT</portlet-mode>
        </supports>
        <portlet-info>
            <title>Spring Portlet</title>
            <short-title>Spring</short-title>
        </portlet-info>
    </portlet>
    You don't need (or even must not) let the portlet load the root application context, because it will detect the one already present. The sequence when you start the server..

    1. ContextLoaderListener detects the contextConfigLocations context parameter and uses that value to load an ApplicationContext (ROOT-CONTEXT)
    2. Portlet named 'Basic' is loaded
    3. Portlet named 'Spring' is loaded, it sees the contextConfigLocations init parameters and uses that value to load an ApplicationContext, before it starts loading it sees if there already is an ApplicationContext loaded by a ContextLoaderListener if so it uses that as a parent.
    4. Portlet named 'BasicSpring' is loaded (see 3)
    5. Portlet named 'helloworld' is loaded, it doesn't have a contextConfigLocations init parameter so it is going to only load the helloworld-portlet.xml and see if an ApplicationContext is already loaded by the ContextLoaderListener (and use that as a parent).

    Which in the end results in 4 ApplicationContexts, 1 Root, 3 Portlet contexts all pointing to the root one.
    Last edited by Marten Deinum; Feb 2nd, 2009 at 05:11 AM.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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