Results 1 to 2 of 2

Thread: ActionSupport NullPointerException on context

  1. #1
    Join Date
    Oct 2004
    Posts
    8

    Default ActionSupport NullPointerException on context

    I've been trying to obtain my ApplicationContext using ActionSupport and am getting a NullPointerException. I'm sure it's something trivial that I'm forgetting, I've just been staring at it too long so was looking for a little help.

    Here's my listener in web.xml:

    Code:
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    
    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>
    My (now gutted) BaseAction to retrieve the context:

    Code:
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    import org.springframework.web.struts.ActionSupport;
    
    public class BaseAction extends ActionSupport &#123;
    
        protected static Log log = LogFactory.getLog&#40;BaseAction.class&#41;;
        protected String ctxString = getWebApplicationContext&#40;&#41;.toString&#40;&#41;;
        
    &#125;
    Any reference to getWebApplicationContext() in here won't work. I just get a NullPointerException from that line.

    Does anyone have any idea what the problem is? I'm using Tomcat 5.0.

    Thanks in advance,
    Mike

  2. #2

    Cool solution

    The problem is that the application context is not initialised until your object is intialised.
    i.e. - you can't refer to it in your field declarations or your constructor method.
    I just hit the same problem you see.

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  3. Replies: 3
    Last Post: Jul 27th, 2005, 10:41 AM
  4. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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