永发信息网

struts2 自动装配 service=null

答案:3  悬赏:70  手机版
解决时间 2021-05-24 23:03
struts2\spring\hibernate采用自动装配,即第二种装配方式,action中的service总是报NullPointException,郁闷啊?还请高手解决啊!struts代码如下:
package com.hengbao.test.action;
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;
import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;import org.springframework.context.ApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;
import com.hengbao.core.page.Page;import com.hengbao.test.entity.TUser;import com.hengbao.test.service.TUserService;import com.hengbao.test.util.SystemUtils;import com.opensymphony.xwork2.ActionSupport;
public class TUserAction extends ActionSupport { private TUserService tUserService; private TUser tUser; private List tUserList; private int total; private int page; private List rows;
public String query() { HttpServletRequest request = ServletActionContext.getRequest(); Page page_ = new Page(request); ServletContext sc = ServletActionContext.getServletContext(); ApplicationContext ac = WebApplicationContextUtils .getRequiredWebApplicationContext(sc); System.out.println("tUserService:" + tUserService);
page_ = tUserService.query(new Page(null, null)); total = page_.getTotalLine(); page = page_.getCurrentPage(); rows = initRows(page_.getDataList()); return "json"; }
private List initRows(List list) { List mapList = new ArrayList(); for (int i = 0; i < list.size(); i++) { Map cellMap = new HashMap(); cellMap.put("id", ((TUser) list.get(i)).getId().toString()); cellMap.put("cell", new Object[] { ((TUser) list.get(i)).getName(), ((TUser) list.get(i)).getLoginName(), ((TUser) list.get(i)).getSex(), SystemUtils.formatDateForBirthday(((TUser) list.get(i)) .getBirthday()), ((TUser) list.get(i)).getMobilePhone(), ((TUser) list.get(i)).getHomePhone(), ((TUser) list.get(i)).getHomeAddress(), ((TUser) list.get(i)).getJobPhone(), ((TUser) list.get(i)).getJobAddress(), ((TUser) list.get(i)).getEmail(), ((TUser) list.get(i)).getPostcode() }); mapList.add(cellMap); } return mapList; }
public TUserService getTUserService() { return this.tUserService; }
public void setTUserService(TUserService tUserService) { this.tUserService = tUserService; }
public TUser getTUser() { return this.tUser; }
public void setTUser(TUser tUser) { this.tUser = tUser; }
public List getTUserList() { return this.tUserList; }
public void setTUserList(List tUserList) { this.tUserList = tUserList; }
public int getTotal() { return total; }
public void setTotal(int total) { this.total = total; }
public int getPage() { return page; }
public void setPage(int page) { this.page = page; }
public List getRows() { return rows; }
public void setRows(List rows) { this.rows = rows; }}

<package name="tUser" extends="json-default"> <action name="*TUser" class="com.hengbao.test.action.TUserAction" method="{1}"> <result name="addSuccess" type="redirectAction"></result> <result name="updateSuccess" type="redirectAction"></result> <result name="deleteSuccess" type="redirectAction"></result> <result name="querySuccess" type="redirectAction"></result> <result name="json" type="json"> <param name="includeProperties"> total,page,rows.* </param> </result> <result name="success">/{1}TUser.jsp</result> </action> </package>spring代码如下:<bean id="tUserService" class="com.hengbao.test.service.imp.TUserServiceImp" />dao代码如下:<bean id="tUserDao" class="com.hengbao.test.dao.imp.TUserDaoImp" />web.xml代码如下:<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> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>说明:(1)applicationContext.gebBean("tUserService") 可以取到正确的service,代表spring配置文件已经加载成功;(2)运行中没有报任何异常;
最佳答案

你没有 下载 struts-spring-plugin 的插件jar

全部回答
把错误贴出来看看呢~
你的action没有进行spring的配置
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
广东话里的“白虎”什么意思
永城市商丘OYO芒果快捷酒店地址在哪里啊
怎么克服心理自闭证
龙沙区齐齐哈尔龙沙区绍梅皮肤健康养生馆在什
比尔马可帝国我没进去啊杂回事
前杨村这个地址在什么地方,我要处理点事
怎么才能叫一个人长胖啊????
现代成功人士名言,怎样快速成功,成为成功人
魔兽世界从哪去外域?
修武县焦作范氏祖塋在什么地方啊,我要过去处
松下和索尼电视哪个好,索尼,日立,松下,夏
盗墓笔记7更新到哪了 谁有?
内蒙古包头市有铸造厂吗
求机电一体化的毕业设计样本
宁远县永州宁远健华大药房地址在哪里啊
推荐资讯
洪湖市荆州章光101(洪湖分店)怎么去啊,谁知
那个兔八哥的游戏叫什么
鼓楼区开封食百汇振河美食广场怎么去啊,谁知
如梦令李清照名句赏析,如梦令 李清照的名句
创新声卡怎样才能让别人听的声音跟我一样
电脑为何突然重启?
罗田县黄冈同济药店地址有谁知道?有点事想过
急!急!急!怎样充G币
富锦市佳木斯杨久洲皮肤性病专科在哪里啊,我
青春寄语赏析,赞美青年的诗句
写作时,怎么才能做到“以静写动,以动衬静”,
氨气喷泉实验用喷泉实验装置进行喷泉实验,上
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?