Announcement Announcement Module
Collapse
No announcement yet.
Error creating bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error creating bean

    Hi All,

    i am having problems while trying to run an app on Jboss server.
    this is the error log i am getting

    Code:
    Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [account.hbm.xml] cannot be opened because it does not exist
    Caused by: 
    java.io.FileNotFoundException: class path resource [account.hbm.xml] cannot be opened because it does not exist
    	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135)
    	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:656)
    	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.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3854)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4359)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:582)
    	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
    	at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
    	at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    	at org.apache.catalina.core.StandardContext.init(StandardContext.java:5310)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:582)
    	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
    	at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
    	at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    	at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
    	at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
    	at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
    	at org.jboss.web.WebModule.startModule(WebModule.java:83)
    	at org.jboss.web.WebModule.startService(WebModule.java:61)
    	at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
    	at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
    	at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:582)
    	at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    	at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    my applicationContext.xml

    Code:
    <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    		<property name="url" value="jdbc:mysql://localhost/mycrm?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=utf-8"/>
    		<property name="username" value="root"/>
    		<property name="password" value="root"/>
    	</bean>
    	
    	
    	<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="myDataSource"/>
    		<property name="mappingResources">
    			<list>
    				<value>account.hbm.xml</value>
    				<value>address.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">				
    				<props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                </props>
    		</property>
    	</bean>
    i have the hibernate xml files under web-inf/resources.

    Please help me to resolve this problem

  • #2
    Hi Saurav,

    Normaly spring seeks for hibernate mapping files in the class path. So you should put those in to the WEB-INF/classes.

    or you can use the following mapping if you want to keep the files in the location as you mentioned above.

    Code:
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="myDataSource"/>
    		<property name="mappingLocations">
    			<list>
    				<value>WEB-INF/resources/account.hbm.xml</value>
    				<value>WEB-INF/resources/address.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">				
    				<props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                </props>
    		</property>
    	</bean>
    You should use mappingLocations instead of mappingResources.

    -/Viraj

    Comment


    • #3
      thanks a lot Viraj for the help.
      It worked

      Comment


      • #4
        hbm.xml .. does not exist error

        I'm getting the same error hbm.xml] can be opened because it does not
        exist. I tried all the recommendations - changing to mappingLocations and
        putting it in WEB-INF/classes and setting my environment classpath variable to c:/eclipse/workspace/.../WEB-INF/classes and it still doesn't work.

        Comment

        Working...
        X