当前位置: 代码迷 >> Java Web开发 >> ssh中action调用service层出现空指针错误
  详细解决方案

ssh中action调用service层出现空指针错误

热度:7877   发布时间:2013-02-25 21:23:02.0
ssh中action调用service层出现空指针异常
Action的代码如下:
public class ShowGoodsAction extends ActionSupport {

private GoodsService goodsService;
public GoodsService getGoodsService() {
return goodsService;
}
private Goods goods;
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public void setGoodsService(GoodsService goodsService) {
this.goodsService = goodsService;
}
public String showGoods()
{
System.out.println("hhhhh");
List list=goodsService.showGoods(goods);
Map session=ActionContext.getContext().getSession();
session.put("list",list);
System.out.println("list====="+list);
return "success";
}
}




spring配置文件:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver">
</property>
<property name="url"
value="jdbc:jtds:sqlserver://localhost:1433/Newdb">
</property>
<property name="username" value="ss"></property>
<property name="password" value="123"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/why/shopping/pojo/Goods.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="mypointcut" expression="execution(* com.why.shopping.dao.hibernate.*.*(..))"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="mypointcut"/>
</aop:config>
 
<bean id="showGoodsDao" class="com.why.shopping.dao.hibernate.GoodsManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="showGoodsSercive" class="com.why.shopping.serviceImpl.GoodsServiceImpl">
<property name="goodsDao" ref="showGoodsDao"></property>
</bean>
<bean id="showAction" class="com.why.shopping.action.ShowGoodsAction">
<property name="goodsService" ref="showGoodsSercive"></property>
  </bean>
</beans>


出错信息:

java.lang.NullPointerException
com.why.shopping.action.ShowGoodsAction.showGoods(ShowGoodsAction.java:30)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Sat Sep 23 10:06:45 CST 2017
  • 最近登录:Sat Sep 23 10:06:45 CST 2017
  • 最近登录:Sat Sep 23 10:06:45 CST 2017
  • 最近登录:Sat Sep 23 10:06:45 CST 2017
  • 最近登录:Sat Sep 23 10:06:45 CST 2017