问题描述
各位大侠看下啊,刚配置好spring2.0+struts2.0+hibernate3.0程序发布后可以运行是可以保存查询数据,但我想在java里调式就出现了错误首先说下我的applicationContext.xml文件存放路径为WEB-INF文件夹下里面有配置了bean<beanid="sysRolesDAO"class="com.st.dao.iface.imp.SysRolesDAOImp"><propertyname="sessionFactory"><refbean="sessionFactory"/></property></bean>其中publicclassSysRolesDAOImpextendsHibernateDaoSupportimplementsSysRolesDAO然后我执行一个Test.java代码如下publicstaticvoidmain(String[]args){ApplicationContextctx=newClassPathXmlApplicationContext("classpath*:applicationContext.xml");SysRolesDAOsysRolesDAO=(SysRolesDAO)ctx.getBean("sysRolesDAO");inti=sysRolesDAO.getSysRoles().size();System.out.println(i);}控制台输出为:2009-04-1514:32:49,109INFO(org.springframework.context.support.ClassPathXmlApplicationContext:383)-Refreshingorg.springframework.context.support.ClassPathXmlApplicationContext@16f8cd0:displayname[org.springframework.context.support.ClassPathXmlApplicationContext@16f8cd0];startupdate[WedApr1514:32:49CST2009];rootofcontexthierarchy2009-04-1514:32:49,187INFO(org.springframework.context.support.ClassPathXmlApplicationContext:398)-Beanfactoryforapplicationcontext[org.springframework.context.support.ClassPathXmlApplicationContext@16f8cd0]:org.springframework.beans.factory.support.DefaultListableBeanFactory@14fe5c2009-04-1514:32:49,203INFO(org.springframework.beans.factory.support.DefaultListableBeanFactory:276)-Pre-instantiatingsingletonsinorg.springframework.beans.factory.support.DefaultListableBeanFactory@14fe5c:definingbeans[];rootoffactoryhierarchyExceptioninthread"main"org.springframework.beans.factory.NoSuchBeanDefinitionException:Nobeannamed'sysRolesDAO'isdefinedatorg.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)atorg.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:914)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)atorg.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:757)atcom.st.Test.main(Test.java:15)
解决方案
解决方案二:
sysRolesDAO没有定义,我也不知道是什么原因,帮你顶一个
解决方案三:
路过
解决方案四:
没看出来
解决方案五:
防止下沉!问题真郁闷希望快点解决啊
解决方案六:
你applicationContext.xml文件明明是放在web-inf下面,你用这个怎么能找到("classpath*:applicationContext.xml");
解决方案七:
标签错了!
解决方案八:
今天刚学的spring。。。
解决方案九:
引用5楼xionghj的回复:
你applicationContext.xml文件明明是放在web-inf下面,你用这个怎么能找到("classpath*:applicationContext.xml");
ApplicationContextctx=newClassPathXmlApplicationContext("classpath*:applicationContext.xml");改成ApplicationContextctx=newClassPathXmlApplicationContext("/WEB-INF/applicationContext.xml");
解决方案十:
引用8楼zfc827的回复:
引用5楼xionghj的回复:你applicationContext.xml文件明明是放在web-inf下面,你用这个怎么能找到("classpath*:applicationContext.xml");ApplicationContextctx=newClassPathXmlApplicationContext("classpath*:applicationContext.xml");改成ApplicationContextctx=newClassPathXmlApplicationContext("/WEB-INF/applicationContext.xml");
赞同