Announcement Announcement Module
Collapse
No announcement yet.
BeanCreationException : I can't seem to debug Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanCreationException : I can't seem to debug

    Please can anyone help me figure out why I get this error. This is my application context
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    		http://www.springframework.org/schema/util 
    
    http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    
    	<!-- Define Data Source Object -->
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url"
    			value="jdbc:mysql://localhost:3306/etranscript" />
    		<property name="username" value="username" />
    		<property name="password" value="password" />
    	</bean>
    	
    	
    	<!-- Define Hibernate Session Factory Object -->
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="mappingResources">
    			<list>
    				<value>com/psi/etranscript/model/graduate.hbm.xml</value>
    				<value>com/psi/etranscript/model/pricelist.hbm.xml</value>
    				<value>com/psi/etranscript/model/recipient.hbm.xml</value>
    				<value>com/psi/etransript/model/request.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					org.hibernate.dialect.MySQLDialect
    				</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.hbm2ddl.auto">update</prop>
    				<prop key="hibernate.cglib.use_reflection_optimizer">
    					true
    				</prop>
    				<prop key="hibernate.cache.provider_class">
    					org.hibernate.cache.HashtableCacheProvider
    				</prop>
    			</props>
    		</property>
    	</bean>
    	
    
    	<!-- Define the Dao Objects -->
    	<bean id="graduateDao"
    		class="com.psi.etranscript.dao.hibernate.GraduateDaoImpl">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	
    	<bean id="recipientDao" class="com.psi.etranscript.dao.hibernate.RecipientDaoImpl">
    		<property name="sessionFactory" ref="sessionFactory" />	
    	</bean>
    	
    	<bean id="priceListDao" class="com.psi.etranscript.dao.hibernate.PriceListDaoImpl"> 
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	
    	<bean id="requestDao" class="com.psi.etranscript.dao.hibernate.RequetDaoImpl">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	
    	
    	<!-- Define the Service Objects -->
    	<bean id="graduateService" class="com.psi.etranscript.service.impl.GraduateServiceImpl">
    		<property name="graduateDao" ref="graduateDao" />
    	</bean>
    	
    	<bean id="RecipientService" class="com.psi.etranscript.service.impl.RecipientServiceImpl">
    		<property name="recipientDao" ref="recipientDao" />
    	</bean>
    	
    	<bean id="RequestService" class="com.psi.etranscript.service.impl.RequestServiceImpl">
    		<property name="requestDao" ref="requestDao" />
    	</bean>
    	
    	<bean id="priceListService" class="com.psi.etranscript.service.impl.PriceListServiceImpl">
    		<property name="priceListDao" ref="priceListDao" />
    	</bean>
    	
    </beans>
    And this is the error log
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [appContext.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
    Caused by: java.lang.ExceptionInInitializerError
    	at org.hibernate.cfg.Configuration.reset(Configuration.java:168)
    	at org.hibernate.cfg.Configuration.<init>(Configuration.java:187)
    	at org.hibernate.cfg.Configuration.<init>(Configuration.java:191)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:60)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:779)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:561)
    	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
    	at com.psi.etranscript.util.impl.ServiceLocatorImpl.<init>(ServiceLocatorImpl.java:24)
    	at com.psi.etranscript.test.Test.testServiceLocator(Test.java:14)
    	at com.psi.etranscript.test.Test.main(Test.java:10)
    Caused by: java.lang.NullPointerException
    	at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144)
    	at org.hibernate.cfg.Environment.<clinit>(Environment.java:524)
    	... 26 more
    Please any help will be really appreciated

  • #2
    Please I was hoping to get some responses. I have tried and tried, but i can't seem to find a solution. Please can anyone direct me on what I may be doing wrong. Thanks

    Comment


    • #3
      Take a look at Hibernate's ConfigHelper and see why it fails in getResourceAsStream(..) line 144. No need to debug from the beginning.

      Joerg

      Comment


      • #4
        Jorg, thanks for your reply. I have tried figuring out why this error : java.lang.NullPointerException at org.hibernate.util.ConfigHelper.getResourceAsStrea m(ConfigHelper.java:144) should be occuring but have been unable to.

        Please with the application context provided in the thread can anyone direct me on what could possibly be going wrong.

        Thankyou.

        Comment


        • #5
          I decided to see if I could break down the app to a smaller level to see how easy it will be to track the error

          When tested and saw that the datasource is being created so there is no problem with this bean.

          As for the session factory bean I changed the bean entry in my application context to this
          Code:
          <bean id="sessionFactory"
          		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          		<property name="dataSource" ref="dataSource" />
          		<property name="mappingResources">
          			<list>
          				<value>
          					com/psi/etranscript/model/graduate.hbm.xml
          				</value>
          			</list>
          		</property>
          		
          		<property name="hibernateProperties">
          			<value>
          				hibernate.dialect=org.hibernate.dialect.MySQLDialect
          			</value>
          		</property>
          	</bean>
          And I still get the error. I believe this configuration is as basic as it can get, so I doubt if it is from the application context entry for session factory.

          I have done alot of googling and a couple of people seem to equally have encountered this problem. Unfortunately I didn't find any solutions.

          Any ideas..??

          By the way I am using Eclipse Europa to test this - don't know if that helps.

          Thanks

          Comment


          • #6
            I have looked into Hibernate's code for the potential reasons - and I can't see anything obviously wrong. What it is actually trying to do is to load "/hibernate.properties" from the classpath:

            Code:
            public static InputStream getResourceAsStream(String resource) {
            	String stripped = resource.startsWith("/") ?
            			resource.substring(1) : resource;
            
            	InputStream stream = null;
            	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            	if (classLoader!=null) {
            		stream = classLoader.getResourceAsStream( stripped );
            	}
            	if ( stream == null ) {
            		stream = Environment.class.getResourceAsStream( resource );
            	}
            	if ( stream == null ) {
            		stream = Environment.class.getClassLoader().getResourceAsStream( stripped );
            	}
            	if ( stream == null ) {
            		throw new HibernateException( resource + " not found" );
            	}
            	return stream;
            }
            Now this implementation should be nearly completely null-safe. In the most recent version line 144 is the one in blue. In this line only one pointer can be null: Class.getClassLoader(). And indeed null is a valid return type. It says null represents the bootstrap classloader in these cases. (Of course the source code might have changed but I can't see anything else having a null pointer.)

            I don't know how you got Hibernate's Environment.class loaded by the bootstrap classloader. That's usually not where it belongs to. So you either change your classpath setup - or you might simply add an empty hibernate.properties into the root of your classpath since this prevents the code from even reaching the line.

            Joerg
            Last edited by Jörg Heinicke; Nov 12th, 2007, 10:41 PM.

            Comment


            • #7
              Joerg thanks very much for your reply.

              I find this very strange indeed. I tried seeing if I could use an entirely different environment (outside eclipse) and so decided to test it in as a war deployed on Tomcat. Guess what? Worked perfectly.

              I created a hibernate.properties file and placed in my classpath, unfortunately this too didn't solve the problem. I don't know if my classpath is incorrectly set, but I strongly doubt this.

              As I said, I don't have problems setting up other beans in my application context asides the sessionFactory.

              I will do further probing, but thanks so far for your assitance.

              Comment


              • #8
                Hi, Have you found a solution to this problem? I am running it on tomcat but I receive the same problem. I have been struggling with it for 2 days now. Any help will be appreciated. thanks

                Comment

                Working...
                X