Announcement Announcement Module
Collapse
No announcement yet.
ERROR - Context initialization failed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ERROR - Context initialization failed

    Code:
    ERROR - Context initialization failed
    java.lang.ExceptionInInitializerError
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.springframework.util.ClassUtils.forName(ClassUtils.java:87)
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:62)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:332)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:298)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:235)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:184)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:188)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:146)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:99)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:103)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:71)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:80)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
    	at com.palm.util.Context.<clinit>(Context.java:20)
    	at com.palm.fnur.service.impl.FnuServiceImpl.<clinit>(FnuServiceImpl.java:21)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.springframework.util.ClassUtils.forName(ClassUtils.java:87)
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:62)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:332)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:298)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:235)
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:184)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:188)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:146)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:99)
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:115)
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:83)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262)
    	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:230)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:156)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3212)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:3554)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:774)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:760)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:548)
    	at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:260)
    	at org.apache.catalina.core.StandardHost.install(StandardHost.java:741)
    	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:512)
    	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:354)
    	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:671)
    	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1149)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:707)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1141)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:316)
    	at org.apache.catalina.core.StandardService.start(StandardService.java:450)
    	at org.apache.catalina.core.StandardServer.start(StandardServer.java:2143)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:463)
    	at org.apache.catalina.startup.Catalina.execute(Catalina.java:350)
    	at org.apache.catalina.startup.Catalina.process(Catalina.java:129)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:156)
    Caused by: java.lang.NullPointerException
    	at com.palm.fnur.service.impl.UserServiceImpl.<clinit>(UserServiceImpl.java:13)
    Please tell me why Iam getting this error. this happens when I add a new entry(marked in below code as bold) in applicationContext.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    	<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    	"http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName">
    			<value>oracle.jdbc.driver.OracleDriver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:oracle:thin:@192.168.1.18:1521:regac</value>
    		</property>
    		<property name="username">
    			<value>fnur</value>
    		</property>
    		<property name="password">
    			<value>fnur</value>
    		</property>
    	</bean>
    
    
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource"><ref bean="dataSource"/></property>
    		<property name="mappingResources">
    			<list>
    				<value>com/palm/fnur/model/entities/FnuLookup.hbm.xml</value>
    				<value>com/palm/fnur/model/entities/FnuRedirect.hbm.xml</value>
    				<value>com/palm/fnur/model/entities/BusinessUsers.hbm.xml</value>				
    				<value>com/palm/fnur/model/entities/FnuAdminUsers.hbm.xml</value>						
    				<value>com/palm/fnur/model/entities/FnuHitHistory.hbm.xml</value>	
    				<value>com/palm/fnur/model/entities/FnuPageNotFound.hbm.xml</value>
    				<value>com/palm/fnur/model/entities/FnuHit.hbm.xml</value>
    				<value>com/palm/fnur/model/entities/FnuNotFoundHit.hbm.xml</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory"/>
    		</property>
    	</bean>
    
    	<bean id="fnuDAO" class="com.palm.fnur.dao.impl.FnuDAOImpl">
    		<property name="hibernateTemplate">
    			<ref local="hibernateTemplate" />
    		</property>
    	</bean>
    	<bean id="userDAO" class="com.palm.fnur.dao.impl.UserDAOImpl">
    		<property name="hibernateTemplate">
    			<ref local="hibernateTemplate"/>
    		</property>
    	</bean>
    
    	<bean id="catalogPage" class="com.palm.fnur.page.CatalogPage">
    	  <property name="fnuDAO" ref="fnuDAO"/>
    	</bean>
    	<bean id="iFnuService" class="com.palm.fnur.service.impl.FnuServiceImpl">
    	  <property name="fnuDAO" ref="fnuDAO"/>
    	</bean>
    	<bean id="iUserService" class="com.palm.fnur.service.impl.UserServiceImpl">
    	  <property name="userDAO" ref="userDAO"/>
    	</bean>
    </beans>

  • #2
    Is it possible to see the code you are running? Specifically UserServiceImpl and point out which line it's getting the NullPointerException line on.

    Comment


    • #3
      this is the code for UserServiceImpl.java :
      The line giving error is marked as bold

      Code:
      package com.palm.fnur.service.impl;
      
      import java.util.ArrayList;
      
      import com.palm.fnur.dao.IUserDAO;
      import com.palm.fnur.service.IUserService;
      import com.palm.util.Context;
      
      public class UserServiceImpl implements IUserService {
      
      	private static IUserDAO iUserDAO;
      	static {
      		iUserDAO = (IUserDAO)Context.getContext().getBean("userDAO");
      	}
      
      	public ArrayList getUserlist() {
      		return iUserDAO.getUserlist();
      	}
      
      	public void setUserDAO(final IUserDAO userDAO) {
      	}
      }
      Same funtionality is working with iFnuService entry
      Code:
      <bean id="iFnuService" class="com.palm.fnur.service.impl.FnuServiceImpl">
      	  <property name="fnuDAO" ref="fnuDAO"/>
      	</bean>
      <bean id="iUserService" class="com.palm.fnur.service.impl.UserServiceImpl">
      	  <property name="userDAO" ref="userDAO"/>
      	</bean>

      Comment


      • #4
        You are looking up the dependency in a static block, not quite sure why. Spring allows you to inject dependencies, you shouldn't have to look them up like this.
        http://www.springframework.org/docs/...tter-injection
        http://martinfowler.com/articles/injection.html

        Code:
        package com.palm.fnur.service.impl;
        
        import java.util.ArrayList;
        
        import com.palm.fnur.dao.IUserDAO;
        import com.palm.fnur.service.IUserService;
        import com.palm.util.Context;
        
        public class UserServiceImpl implements IUserService {
        
        	private IUserDAO iUserDAO;
        
        	public ArrayList getUserlist() {
        		return iUserDAO.getUserlist();
        	}
        
        	public void setUserDAO(final IUserDAO userDAO) {
                         this.iuserDAO = userDAO;
        	}
        }

        Comment


        • #5
          Thanks it worked!!!

          Comment


          • #6
            Ahhh the power of Spring . I would really recommend having a read through the reference manual and looking at the sample applications. It can save hours of swearing, pulling out of hair and broken keyboards .

            Comment


            • #7
              Originally posted by karldmoore View Post
              Ahhh the power of Spring . I would really recommend having a read through the reference manual and looking at the sample applications. It can save hours of swearing, pulling out of hair and broken keyboards .
              I think this is a very nice and pictorial circumscription of RTFM

              Sorry, could not resist
              Andreas

              Comment


              • #8
                Originally posted by Andreas Senft View Post
                I think this is a very nice and pictorial circumscription of RTFM
                I'm very innocent and therefore wouldn't have the slightest idea what that stands for .

                Comment

                Working...
                X