我想创建一个简单的Web项目应用程序。我正在使用struts2和hibernate,我是这两个框架的新手,我收到了这个错误:
Unable to instantiate Action, org.project.actions.UserAction, defined for 'saveUser' in namespace '/'An AnnotationConfiguration instance is required to use com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:306) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:387) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:458) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76) root cause org.hibernate.MappingException: An AnnotationConfiguration instance is required to use org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1634) org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1589) org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1568) org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542) org.hibernate.cfg.Configuration.configure(Configuration.java:1462) org.hibernate.cfg.Configuration.configure(Configuration.java:1448) org.project.actions.UserAction.(UserAction.java:23) sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) java.lang.reflect.Constructor.newInstance(Unknown Source) java.lang.Class.newInstance0(Unknown Source) java.lang.Class.newInstance(Unknown Source) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:119) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139) com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109) com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:287) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:387) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:458) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76)
我尝试使用AnnotationConfiguration()创建SessionFactory,但是会发生同样的错误。请帮忙。提前致谢。
答案 0 :(得分:0)
这是我的愚蠢错误。我正在使用Full Hibernate插件。使用此插件时,您不必为Session对象创建SessionFactory对象。我的错误是我忘了删除SessionFactory对象和Session对象。 : - )