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)
编写的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文件,那么就仔细核对配置中的路径,如果都对的话重新编译一下
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。