Announcement Announcement Module
Collapse
No announcement yet.
Problem loading applicationContext.xml in integrating spring2.5 to struts2+hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem loading applicationContext.xml in integrating spring2.5 to struts2+hibernate

    HI,
    I have injected springs into struts2 using applicationContext.xml file.While
    inserting records into database,am getting spring session by again loading
    applicationContext.xml file using a java class.Here is that java class:

    package service;
    import org.springframework.context.ApplicationContext;
    import org.springframework.web.context.support.WebApplica tionContextUtils;
    import java.util.Map;
    import javax.servlet.ServletRequest;
    import javax.servlet.http.HttpServletRequest;

    public class ServiceFinder {
    private static ApplicationContext ctx = null;
    public static Object getBean(ServletRequest request, String beanName) {
    if (ctx == null) {
    if (!(request instanceof HttpServletRequest)) {
    throw new IllegalArgumentException(
    "Can only process HttpServletRequest");
    }
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    ctx = getContext(httpRequest);
    }

    Object obj= new Object();
    return obj;

    }

    /**
    * Allows test cases to override where application context obtained from.
    *
    * @param httpRequest which can be used to find the
    * <code>ServletContext</code>
    *
    * @return the Spring application context
    */
    public static ApplicationContext getContext(HttpServletRequest
    httpRequest) {
    return WebApplicationContextUtils.getRequiredWebApplicati onContext(
    httpRequest.getSession().getServletContext());
    }
    }



    So i have just used getHibernateTemplate() method inorder to do transactions
    in my hibernatedao implementation.
    My problem is: if i don't write above java class to explicitly load
    applicationContext.xml file am getting getHibernateTemplate() as null and
    getting a NPE.Why is it happening?I would like to use getHibernateTemplate()
    method without explicitly loading appContext.xml file since its already
    loaded at the time of starting my application(deploying the project) using
    tomcat..Any idea is greatly appreciated?

    Plz reply as early as possible...........replies plzzzzzz

  • #2
    Hello HidhiR . I have a problem about integrate spring2.5,hibernate3.2 and struts2,when i integrate them ,my tomcat5.5 can't start my application ,could you tell me, how to integrate them? If you like ,could you show your configuration files and lib list to me? Thank you!

    Comment

    Working...
    X