问题描述
Errorinformation不知道哪里配置错了。java.lang.NullPointerExceptionatjflying.common.action.TreeExtAction.treeExtId(TreeExtAction.java:31)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atcom.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)atcom.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)atcom.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)atorg.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atorg.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atorg.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atorg.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atorg.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atorg.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atcom.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)atorg.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)atorg.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)atorg.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)atorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)atjava.lang.Thread.run(Thread.java:619)我在Application.xml配置是<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><propertyname="configLocation"value="classpath:hibernate.cfg.xml"></property></bean><!--事务管理器--><beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><propertyname="sessionFactory"><reflocal="sessionFactory"/></property></bean></beans>用注解的方式注解@Autowired到Struts2的Action里但service里的定义在调试是为null@Controller("treeExtAction")@Scope("prototype")publicclassTreeExtActionextendsActionSupport{@AutowiredprivateITreeExtiTreeExt;privateTreeExttreeExt;//实体publicStringtreeExtId(){try{System.out.println("Test");treeExt=iTreeExt.getTreeExt(2);//在这里,ITreeExt在调试步入到这里时,iTreeExt为null然后被catch捕获treeExt.setTrUniqunecode("TreeExt");System.out.println("Mark");}catch(Exceptione){e.printStackTrace();}return"treeext";}publicTreeExtgetTreeExt(){returntreeExt;}publicvoidsetTreeExt(TreeExttreeExt){this.treeExt=treeExt;}}=========================================================service@ServicepublicclassTreeExtImplsimplementsITreeExt{@AutowiredprivateITreeExtDaotreeExtDao;/*privateSessionFactorysessionFactory;publicvoidsetSessionFactory(SessionFactorysessionFactory){this.sessionFactory=sessionFactory;}*/publicvoidaddTreeExt(TreeExttreeExt){this.treeExtDao.addTreeExt(treeExt);}publicvoiddelTreeExt(inttreeExtId){this.treeExtDao.delTreeExt(treeExtId);}publicPagergetAllTreeExt(){returnnull;}publicTreeExtgetTreeExt(inttreeExtid){returnthis.treeExtDao.getTreeExt(treeExtid);}publicvoidupdateTreeExt(TreeExttreeExt){this.treeExtDao.updateTreeExt(treeExt);}}=============================================================dao@RepositorypublicclassTreeExtDaoImplsimplementsITreeExtDao{@AutowiredprivateHibernateTemplatehibernateTemplate;publicvoidaddTreeExt(TreeExttreeExt){this.hibernateTemplate.save(treeExt);}publicvoiddelTreeExt(inttreeExtId){this.hibernateTemplate.delete(getTreeExt(treeExtId));}publicPagergetAllTreeExt(){//TODOAuto-generatedmethodstubreturnnull;}publicTreeExtgetTreeExt(inttreeExtid){returnthis.hibernateTemplate.load(TreeExt.class,treeExtid);}publicvoidupdateTreeExt(TreeExttreeExt){this.hibernateTemplate.update(treeExt);}}通过接口来访问。