社区
Java EE
帖子详情
Struts2+Spring+JPA(Hibernate)报空指针问题?
九两银
2011-05-14 03:24:02
有没有人遇到同样的问题··代码执行到Action里时调用biz方法时返回值是空的,报空指针了。。
但测试这个biz方法时没问题的。。。
...全文
101
14
打赏
收藏
Struts2+Spring+JPA(Hibernate)报空指针问题?
有没有人遇到同样的问题··代码执行到Action里时调用biz方法时返回值是空的,报空指针了。。 但测试这个biz方法时没问题的。。。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
九两银
2011-05-14
打赏
举报
回复
有没人来帮忙整一下啊
软件开发那些事儿
2011-05-14
打赏
举报
回复
如果我没有记错的话,”我已经引用了这段代码了beans的<context:component-scan base-package="com.demo" />“spring的Ioc容器里已经有了这个action的bean,只要加上struts-spring插件让spring管理action,然后再加上class="IndexAction",说明一下,spring的Ioc容器会按照action的类名来创建bean。
九两银
2011-05-14
打赏
举报
回复
[Quote=引用 10 楼 centre10 的回复:]
补充一下:由于你采用的annotation,你可以这么写:
<constant name="struts.devMode" value="true"></constant>
<package name="IndexAction" namespace="/" extends="struts-default">
<action name="indexAction" class="IndexAct……
[/Quote]
我已经引用了这段代码了beans的<context:component-scan base-package="com.demo" />
软件开发那些事儿
2011-05-14
打赏
举报
回复
同时还应该加入struts-spring的jar包,让spring管理action
软件开发那些事儿
2011-05-14
打赏
举报
回复
补充一下:由于你采用的annotation,你可以这么写:
<constant name="struts.devMode" value="true"></constant>
<package name="IndexAction" namespace="/" extends="struts-default">
<action name="indexAction" class="IndexAction" method="getAllGoods">
<result name="index">/index.jsp</result>
</action>
</package>
</struts>
软件开发那些事儿
2011-05-14
打赏
举报
回复
<struts>
<constant name="struts.devMode" value="true"></constant>
<package name="IndexAction" namespace="/" extends="struts-default">
<action name="indexAction" class="com.demo.action.IndexAction" method="getAllGoods">
<result name="index">/index.jsp</result>
</action>
</package>
</struts>
Struts。xml
你的action是由struts2的容器管理的,没有用到spring容器里管理的acton,因此,你可以这样写试试:
<constant name="struts.devMode" value="true"></constant>
<package name="IndexAction" namespace="/" extends="struts-default">
<action name="indexAction" class="xxx(spring的actionbean)" method="getAllGoods">
<result name="index">/index.jsp</result>
</action>
</package>
</struts>
chenyinglong0712
2011-05-14
打赏
举报
回复
你在spring中没配置Action中的对象...
九两银
2011-05-14
打赏
举报
回复
我在线关注着··希望有人来解决下
九两银
2011-05-14
打赏
举报
回复
[Quote=引用 5 楼 acherat 的回复:]
biz 没有注入到这个 action 里边。
[/Quote]
可我明明注了,怎么就不起作用呢?在哪需要检查??
AcHerat
2011-05-14
打赏
举报
回复
biz 没有注入到这个 action 里边。
九两银
2011-05-14
打赏
举报
回复
<struts>
<constant name="struts.devMode" value="true"></constant>
<package name="IndexAction" namespace="/" extends="struts-default">
<action name="indexAction" class="com.demo.action.IndexAction" method="getAllGoods">
<result name="index">/index.jsp</result>
</action>
</package>
</struts>
Struts。xml
九两银
2011-05-14
打赏
举报
回复
@Controller("indexAction")
@Scope("prototype")
public class IndexAction extends ActionSupport implements SessionAware{
private GoodsBiz goodsBiz;
public GoodsBiz getGoodsBiz() {
return goodsBiz;
}
@Resource
public void setGoodsBiz(GoodsBiz goodsBiz) {
this.goodsBiz = goodsBiz;
}
private Map<String,Object> session=new HashMap<String, Object>();
public Map<String, Object> getSession() {
return session;
}
public void setSession(Map<String, Object> arg0) {
this.session=session;
}
private int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getAllGoods(){
// try {
List listGoods = goodsBiz.getAllGoods(); //这事报错的地方
count=listGoods.size();
session.put("listGoods", listGoods);
// } catch (Exception e) {
// System.out.println(e.getMessage());
// }
System.out.println("test_Ok");
return "index";
}
这里面的话有问题没?
宁波朱超
2011-05-14
打赏
举报
回复
[Quote=引用楼主 jiuliangyin 的回复:]
有没有人遇到同样的问题··代码执行到Action里时调用biz方法时返回值是空的,报空指针了。。
但测试这个biz方法时没问题的。。。
[/Quote]
明显你的biz没被注入。所以action里调到的biz是空
wl_ldy
2011-05-14
打赏
举报
回复
不知道你的Action是否是让Spring来管理的,如果是的话,那很可能是Spring没有将Action注入进去或者Action中的Service层没有注入到Action中。
Struts2
+
Spring
+
JPA
(
Hibernate
)的jar包
Struts2
+
Spring
+
JPA
(
Hibernate
)项目所需要的jar包
Struts2
+
Spring
2.5 +
JPA
(
hibernate
) + AJAX+ 实例
Struts 2 +
Spring
2 +
JPA
+
hibernate
+ AJAX +实例, 包含依赖jar包。
Spring
+
Spring
Data+
JPA
Spring
MVC+Redis +Solr 个人博客
博客(BIG)系统是企业营销信息化的解决方案,它将企业市场管理、销售管理、服务管理三个领域应用三位一体化,帮助企业提升整体营销管理竞争力、提高销售工作效率、提高服务满意度顾客忠诚度。以满足企业不断丰厚的信息化需求和运营管理需求
Struts1.3+
spring
2.5+
JPA
(
hibernate
) demo
Struts1.3+
spring
2.5+
JPA
(
hibernate
) 实现的一个小示例,比较适合初学者和整合配置查询。
Struts2
.1+
Spring
3.0+
JPA
1.0(
Hibernate
3.3实现)例子
Struts2
.1+
Spring
3.0+
JPA
1.0(
Hibernate
3.3实现)例子 文章分类:Java编程 本文代码是
Spring
2.5各种示例的综合,在此把所有框架升级到最新版本整合一下。
Java EE
67,512
社区成员
225,880
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章