开发者社区> 问答> 正文

web项目报错,快急死了,本人渣渣一枚,请大神解答!谢谢~?报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [cn/itcast/shop/user/vo/User.hbm.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5077)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5591)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

 

 

 

 

 

 

展开
收起
爱吃鱼的程序员 2020-06-08 10:00:04 593 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    编写的action:

     

    packagecn.itcast.shopp.index.action;

    importcom.opensymphony.xwork2.ActionSupport;

    publicclassIndexActionextendsActionSupport{

       /*
       *首页访问的Action
       * 
       */
       
       publicStringexecute(){
          
          return"index";
       }
       

    [applicationContext.xml]中是配置[cn/itcast/shop/user/vo/User.hbm.xml]那一行怎么写的?写法有问题

    回复 @tongcanghai:握手cn/itcast/shop/user/vo/User.hbm.xml的前面加上classpath:我贴在下边了,老兄看一下。。。

     

    structs.xml:

     

    <?xmlversion="1.0"encoding="UTF-8"?>
    <!DOCTYPEstrutsPUBLIC
       "-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN"
       "http://struts.apache.org/dtds/struts-2.3.dtd">

    <structs>

    <constantname="struts.devMode" value="false"/>

    <packagename="shop" extends="struts-default" namespace="/">

    <actionname="index" class="indexAction">
       
       <resultname="index">/WEB-INF/jsp/index.jsp</result>

    </action>

    </package>

    </structs>

    applicationContext.xml:

     

    <?xmlversion="1.0"encoding="UTF-8"?>
    <beansxmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx.xsd">
       
       <!--配置连接池:-->
       <!--引入外部属性文件-->
       <context:property-placeholderlocation="classpath:jdbc.properties"/>
       <!--配置C3P0连接池:-->
       <beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
          <propertyname="driverClass"value="${jdbc.driver}"/>
          <propertyname="jdbcUrl"value="${jdbc.url}"/>
          <propertyname="user"value="${jdbc.user}"/>
          <propertyname="password"value="${jdbc.password}"/>
       </bean>
       
       <!--Hibernate的相关信息-->
       <beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <!--注入连接池-->
          <propertyname="dataSource"ref="dataSource"/>
          <!--配置Hibernate的其他的属性-->
          <propertyname="hibernateProperties">
             <props>
                <propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <propkey="hibernate.show_sql">true</prop>
                <propkey="hibernate.format_sql">true</prop>
                <propkey="hibernate.connection.autocommit">false</prop>
                <propkey="hibernate.hbm2ddl.auto">update</prop>
             </props>
          </property>
          <!--配置Hibernate的映射文件-->
          <propertyname="mappingResources">
             <list>
                <value>cn/itcast/shop/user/vo/User.hbm.xml</value>
                <value>cn/itcast/shop/category/vo/Category.hbm.xml</value>
                <value>cn/itcast/shop/product/vo/Product.hbm.xml</value>
                <value>cn/itcast/shop/categorysecond/vo/CategorySecond.hbm.xml</value>
                <value>cn/itcast/shop/order/vo/Order.hbm.xml</value>
                <value>cn/itcast/shop/order/vo/OrderItem.hbm.xml</value>
                <value>cn/itcast/shop/adminuser/vo/AdminUser.hbm.xml</value>
             </list>
          </property>
       </bean>
       
       <!--事务管理:-->
       <!--事务管理器-->
       <beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          <propertyname="sessionFactory"ref="sessionFactory"/>
       </bean>
       
       <!--开启注解事务-->
       <tx:annotation-driventransaction-manager="transactionManager"/>
       
       <!--Action的配置===========================-->
       
       <!--首页访问的Action-->
       <beanid="indexAction"class="cn.itcast.shopp.index.action.IndexAction"scope="prototype">
          
       </bean>
       

    FileNotFoundException:classpathresource[cn/itcast/shop/user/vo/User.hbm.xml]cannotbeopenedbecauseitdoesnotexist  文件路径不对啊

    握手~

    看看是不是classpath有问题,重新buildpath,一般这种情况都是编译路径有问题,不是说真的找不到那个文件

    谢谢兄台~

    注意看异常的类型:FileNotFoundException,说明这个异常最终是一个文件未找到的异常。再来看异常的信息:classpathresource[cn/itcast/shop/user/vo/User.hbm.xml]cannotbeopenedbecauseitdoesnotexist。

    意思是cn/itcast/shop/user/vo/User.hbm.xml这个文件不能打开因为它不存在。

    看你已经配置好了XML文件,那么就仔细核对配置中的路径,如果都对的话重新编译一下

    2020-06-08 10:00:19
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载