S2SH整合NullPointerException

问题描述

异常信息如下:description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerExceptioncom.axisoft.applicationExercise.action.testAction.testMethod(testAction.java:25)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java.lang.reflect.Method.invoke(Unknown Source)com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)Web.XML信息如下:<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext*.xml</param-value></context-param><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><session-config><session-timeout>30</session-timeout></session-config><listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener>applicationContext.xml信息如下:<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/><property name="url" value="jdbc:oracle:thin:@xxx.xxx.x.xxx:1521:PEGA"/>(IP用"x"代替)<property name="username" value="RAIN"/><property name="password" value="RAIN"/></bean><!-- Hibernate SessionFactory --><bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop><prop key="hibernate.jdbc.fetch_size">50</prop><prop key="hibernate.jdbc.batch_size">50</prop></props></property></bean><!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --><bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- Transaction manager for a single Jdbc DataSource --><bean id="jdbcTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"><property name="transactionManager" ref="transactionManager" /></bean> <!-- Jdbc template for a single Jdbc DataSource --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="testService" class="com.axisoft.applicationExercise.createApplication.service.TestService" />Action信息如下:private ITestService testService;public String testMethod(){/*if (null == testService){System.out.println("果为空");return SUCCESS;}*/String helloStr = testService.testMethod();System.out.println("helloStr : " + helloStr);System.out.println("测试成功 : " + helloStr);return SUCCESS;}public ITestService getTestService(){return testService;}public void setTestService(ITestService testService){this.testService = testService;}Service信息如下:@Overridepublic String testMethod(){//testDao.testMethod();return "Hello";}JSP页面信息如下<a href="testSS.action">&lt;click me&gt;</a><form action="testSS.action"><input type="submit" value="ddd"/></form>哪位请指点一下,错误在哪,当我点击链接或者按钮的时候为什么会出现NullPointerException,谢谢了 问题补充:问题的根源,就是testService没有注入可是为什么呢,struts2的注入很简单的,只用写getter和setter方法,或者用注解可以实现,但是好像要导入spring-struts-3.0.2.RELEASE.jar这个包,请各位再看看我的问题出在哪里,我的所有配置信息已经列出来了。

解决方案

首先看你的配置文件struts没有整合spring。Action testService属性没有使用spring注入,是个null;struts.xml 加入该属性 还需要相应版本的struts2-spring-plugin.jar包<!-- 该属性指定Struts 2中的action由Spring容器创建 --><constant name="struts.objectFactory" value="spring" />然后配置spring action bean 并注入testService
解决方案二:
引用struts2的注入很简单的,只用写getter和setter方法,或者用注解可以实现,但是好像要导入spring-struts-3.0.2.RELEASE.jar这个包,请各位再看看我的问题出在哪里,我的所有配置信息已经列出来了。 问题不是很明确了嘛!只用写getter和setter方法 ???不是吧! spring action bean 并注入testService 这样才能注入 或者 annotation注入!
解决方案三:
testService 应该没有注入实例。可以通过debug启动webserver,程序加上断点跟一下,就知道原因了。
解决方案四:
引用com.axisoft.applicationExercise.action.testAction.testMethod(testAction.java:25) testAction 的第25 行!应该是这行吧引用String helloStr = testService.testMethod(); 貌似 private ITestService testService; 没注入进去 呵呵! 换成 public 或者检查下其他配置

时间: 2024-09-24 18:54:17

S2SH整合NullPointerException的相关文章

java-求问s2sh整合时候需要哪些包

问题描述 求问s2sh整合时候需要哪些包 网上搜到的包大部分都是用的spring.jar这个整合包,而且hibernate版本都是3,每次导包都会少一些包,有没有哪位知道spring3,struts2,hibernate4整合时候需要那些包啊?最好能把所使用的框架的版本也说明下,也可以把某个项目所导入的包的图截一下,新手求教,感激不尽. 解决方案 struts2所必须的jar包五个: struts2-core-2.1.6.jar ------struts2的核心包 freemarker-2.3.

s2sh-【求助】关于S2SH整合遇到的Error creating bean with name &amp;amp;#39;sessionFactory&amp;amp;#39;

问题描述 [求助]关于S2SH整合遇到的Error creating bean with name 'sessionFactory' 这是生成的applicationContext.xml配置: <?xml version="1.0" encoding="UTF-8"?> xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.

s2sh整合做登录模块出现的问题,莫名奇妙

问题描述 刚用s2sh整合做项目(只做了登录模块),都配置好了,可以连接数据库,第一次连接数据库获取数据等操作都可以,但是页面刷新几次之后就连接不上了,页面无法跳转,一直显示正在连接.设了断点,发现可以请求到action,但是一用hibernate向数据库取数据时,就断开了,也没有报错(好像是hibernate取数据卡在那边了,没有打印出hibernate的sql)为什么会有这种情况呢?前几次请求hibernate取数据都可以,刷新多次后就不行了,纳闷呀. 我没有用连接池等.spring配置如下

S2SH整合出错

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'loginAction'definedinfile[D:MyEclipse8.0workspaceOAWebRootWEB-INFclassesapplicationContext-actions.xml]:Initializationofbeanfailed;nestedexceptionisorg.springframe

s2sh整合问题,弄了一天了都没弄出来,拜托大家了!

问题描述 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from fil

S2SH整合时报错多谢各位

问题描述 hibernate配置文件<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!--

S2SH整合,请高手指点

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'loginAction'definedinfile[D:MyEclipse8.0workspaceOAWebRootWEB-INFclassesapplicationContext-actions.xml]:Initializationofbeanfailed;nestedexceptionisorg.springframe

s2sh整合问题 tomcat启动没异常 访问.jsp 和action失败 单独测试struts2成功 hibernate+spring成功

问题描述 web.xml:  <?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:

ojdbc6和ojdbc14在s2sh整合中有什么作用啊

问题描述 如题!!!另外请教高手看看我那些jar包没用的我整理了好久不知道删那些,有时候删了没事有时候就有会报错的antlr-2.7.6.jarasm-2.2.3.jarasm-util-2.2.3.jarcglib-nodep-2.1_3.jarclasses12.jarcommons-collections-2.1.1.jarcommons-dbcp-1.3.jarcommons-fileupload-1.2.2.jarcommons-io-2.0.1.jarcommons-lang-2.5