读取spring配置文件问题!各位大大帮忙下哈

xigen9901 2008-10-04 11:50:27
sessionFactory:在applicationContext-pub.xml文件
userDao:在applicationContext-user.xml文件
<bean id="userDao" class="userModel.dao.impl.UserDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>


源码:
public void testLogin(){
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext-*.xml");(抛异常!!!)
UserDAO userdao =(UserDAO)ac.getBean("userDao");
UserInfo userinfo =userdao.loginUser("xigen", "123456");
System.out.println(userinfo.getUserName());
}


报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in file [E:\workspace\MyOffic\WebRoot\WEB-INF\classes\applicationContext-user.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:\workspace\MyOffic\WebRoot\WEB-INF\classes\applicationContext-pub.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:\workspace\MyOffic\WebRoot\WEB-INF\classes\applicationContext-pub.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
...全文
298 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zou_wei_forever 2008-10-06
  • 打赏
  • 举报
回复
BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext-*.xml");
UserDAO userdao =(UserDAO)factory.getBean("userDao");
这样试试!
B1977 2008-10-05
  • 打赏
  • 举报
回复
你要在applicationContext-user.xml里面把applicationContext-pub.xml导入进来然后
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext-user.xml");
xigen9901 2008-10-05
  • 打赏
  • 举报
回复
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext-*.xml");
我已经读取所有以applicationContext-开头的配置文件了。还要导吗?
怎么导入?

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧