spring常见错误分析

xiaoxiao2021-03-01  5

现象1:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''org.springframework.aop.support.DefaultPointcutAdvisor'' defined in null: Can''t resolve reference to bean ''txAdvice'' while setting property ''advice''; nested exception is 原因:缺少Spring开头的各种包,到Spring2.0 src中编译新的dist目录出来,拷贝全部的springxxx.jar到jpetstore/WEB-INF/lib下。OK。 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~现象2:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sessionFactory'' defined in resource [/WEB-INF/dataAccessContext-hibernate.xml] of ServletContext: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManagerjava.lang.NoClassDefFoundError: javax/transaction/TransactionManager 原因:缺少jta.jar,OK~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~现象3:java.lang.NoClassDefFoundError: org/dom4j/Attribute缺dom4j.jarjava.lang.NoClassDefFoundError: net/sf/ehcache/CacheException缺ehcache.jarjava.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory缺cglib-full.jar~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~现象4:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sessionFactory'' defined in resource [/WEB-INF/dataAccessContext-hibernate.xml] of ServletContext: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: could not instantiate id generatornet.sf.hibernate.MappingException: could not instantiate id generator原因:hbm中id字段的定义为没有定义的sequesce,修改为incname="id"type="string"column="userid">// 原来是sequence. 这样就可以了。~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~现象6:org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''/shop/addItemToCart.do'' defined in ServletContext resource [/WEB-INF/petstore-servlet.xml]: Can''t resolve reference to bean ''petStore'' while setting property ''petStore''; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ''petStore'' is definedorg.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ''petStore'' is defined原因:我使用Struts作为action,当然就不需要使用Spring WEB framework,因此也不需要与之配套的配置文件例如,petstore-servlet.xml,还有remote-servlet.xml ,但是Spring仍旧加载此两个文件,没办法,只好将此两个文件挪动到别的地方,但是又出现找不到这两个文件的IO异常,没办法,只好又拷贝回来,然后把文件内容晴空。终于好用了。原因就是,只要你在web.xml中定义了这个servlet,他就要去找此servlet名字对应的配置文件(servletname-servlet.xml),找不到就出错。ok,现在注释掉web.xml中名字为petstore的servlet定义和影色,删除petstore-servlet.xml文件,哈哈,这下不报告错误了。同理,注释名字为remote的servlet,删除remote-servlet.xml后,重新启动tomcat,这下不报告任何错误了。呵呵。原来如此啊。~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~现象:java.lang.NullPointerExceptionsrx.test.testhibernate.UserDAO.getAll(UserDAO.java:9)srx.test.struts.action.UserAction.execute(UserAction.java:20)原因:Action原来UserDAO // 这个类OKpublic class UserDAO extends HibernateDaoSupport {public List getAll() {return this.getHibernateTemplate().find("select aa from Account aa");}}//这个类需要修改public class UserAction extends ActionSupport {UserDAO dao = new UserDAO(); List accounts = dao.getAll();。。。}修改://UserDAO dao = new UserDAO(); WebApplicationContext wac = this.getWebApplicationContext();UserDAO dao = (UserDAO) wac.getBean("userDAO");

转载请注明原文地址: https://www.6miu.com/read-3650045.html

最新回复(0)