title: Context initialization failed while deploying the gwt application with spring framework
body: <p>Hi i was trying to integrate spring with jpa as the backend for the gwt client. Was tring to do it for the first time and am not able to make a way out this error</p>
  
  <pre><code>15:56:43,315 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'surevyDAOImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: JPA PersistenceProvider returned null EntityManagerFactory - check your JPA provider setup!
      at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:341)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
      at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
      at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
      at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
      at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
      at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
      at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
      at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
      at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      at org.mortbay.jetty.Server.doStart(Server.java:222)
      at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
      at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
      at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
      at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
      at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
      at com.google.gwt.dev.DevMode.main(DevMode.java:311)
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: JPA PersistenceProvider returned null EntityManagerFactory - check your JPA provider setup!
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
      at org.springframework.orm.jpa.EntityManagerFactoryUtils.findEntityManagerFactory(EntityManagerFactoryUtils.java:98)
      at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findNamedEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:510)
      at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:492)
      at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
      at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
      at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:156)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
      at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
      ... 31 more
  Caused by: java.lang.IllegalStateException: JPA PersistenceProvider returned null EntityManagerFactory - check your JPA provider setup!
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
      ... 45 more
  </code></pre>
  
  <p>I have been using the following files:
  web.xml:</p>
  
  <pre><code>&lt;!-- Default page to serve --&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;MobiOffer_GWT.html&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
     &lt;context-param&gt;
          &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/log4j.properties&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/applicationContext.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
      &lt;/listener&gt;
       &lt;filter&gt;
          &lt;filter-name&gt;OpenEntityManagerInViewFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter&lt;/filter-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;entityManagerFactoryBeanName&lt;/param-name&gt;
              &lt;param-value&gt;entityManagerFactory&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;OpenEntityManagerInViewFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
      &lt;/listener&gt;
  
    &lt;servlet&gt;
       &lt;servlet-name&gt;rest-json-api&lt;/servlet-name&gt;
       &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
       &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
       &lt;servlet-name&gt;rest-json-api&lt;/servlet-name&gt;
       &lt;url-pattern&gt;/restServices/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet&gt;
        &lt;servlet-name&gt;gwtDispatcher&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.gwtrpcspring.RemoteServiceDispatcher&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;gwtDispatcher&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/mobioffer_gwt/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I rest-json-api-servlet.xml file which is refered by the above web.xml file is:</p>
  
  <pre><code> &lt;!-- auto scan annotations --&gt;
      &lt;context:component-scan base-package="com.reva.mobioffer.services"/&gt;
  
  
      &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
          &lt;property name="messageConverters"&gt;
              &lt;list&gt;
                  &lt;ref bean="jsonHttpMessageConverter"/&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt;
  
  
      &lt;bean id="jsonHttpMessageConverter"
            class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/&gt;
  
      &lt;bean class="com.reva.mobioffer.views.MyContentNegotiatingViewResolver"&gt;
          &lt;property name="mediaTypes"&gt;
              &lt;map&gt;
                  &lt;entry key="json" value="application/json"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
          &lt;property name="defaultContentType" value="application/json"/&gt;
          &lt;property name="defaultViews"&gt;
              &lt;list&gt;
                  &lt;bean class="com.reva.mobioffer.views.JSONView"/&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I was also using applicationContext.xml file but i was not sure what exactly is the use of this xml file( i could see that the jpa information is mentioned through it)</p>
  
  <pre><code>&lt;context:component-scan base-package="com.reva.mobioffer.domain"/&gt;
  
      &lt;context:annotation-config/&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="mobioffer"/&gt;
      &lt;/bean&gt;
      &lt;bean id="persistenceUnitManager"
            class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"&gt;
          &lt;property name="persistenceXmlLocation"&gt;
              &lt;value&gt;classpath:META-INF/persistence.xml&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="persistenceAnnotation"
              class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
              /&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/&gt;
  
      &lt;!-- Transaction manager for a single EntityManagerFactory (alternative to JTA) --&gt;
      &lt;bean id="transactionManager"
            class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;/bean&gt;
   &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;
  </code></pre>
  
  <p>this was also throwing me an exception as cannot create the bean for org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0</p>
  
  <p>the persistance.xml file is located in the META-INF file:</p>
  
  <pre><code>&lt;persistence-unit name="mobioffer" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.Survey&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyLog&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyLogPK&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestion&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestionOptionMap&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestionOptionMapPK&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestionOption&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestionOptionPK&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestionResponse&lt;/class&gt;
          &lt;class&gt;com.reva.mobioffer.domain.entity.SurveyQuestionResponsePK&lt;/class&gt;
  
                  &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:4406/mobioffer" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="root" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="root" /&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>i have been stuck with it since quite a while but could not find a way to resolve it even after a extreme search.
  Thanks</p>