You should ask this question(s) on the spring forum. In any case you
should let the Spring load applicationContext.xml, and not do it
yourself, unless you have a good reason for it.
musachy
On Thu, Mar 6, 2008 at 8:49 AM, RajiR <[EMAIL PROTECTED]> wrote:
>
> 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.WebApplicationContextUtils;
>
> 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.getRequiredWebApplicationContext(
>
> 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
>
> --
> View this message in context:
> http://www.nabble.com/Problem-while-reading-applicationContext.xml-file-automatically-in-integrating-struts2%2Bsprings2.5%2Bhiberante3.2-tp15873124p15873124.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
"Hey you! Would you help me to carry the stone?" Pink Floyd
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]