<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="username" value="ssi"/>
<property name="password" value="ssi"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
 <property name="initialSize" value="1"/>
        <property name="maxActive" value="4"/>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:SqlMapConfig.xml">
</property>
<property name="dataSource" ref="dataSource">
</property>
</bean><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean><bean id="sqlMapClientProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="select*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean><bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean><bean id="userDao" class="com.soft.ssi.dao.UserDaoImpl">
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
</bean><bean id="userService" class="com.soft.ssi.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userServicePrxy" parent="sqlMapClientProxyFactoryBean">
<property name="target" ref="userService"></property>
</bean><bean id="UserAction" class="com.soft.ssi.web.UserAction">
<property name="userService" ref="userService"></property>
</bean></beans>package com.soft.ssi.web;
import com.opensymphony.xwork2.ActionSupport;
import com.soft.ssi.po.UserInfo;
import com.soft.ssi.service.UserService;
public class UserAction extends ActionSupport{

private UserService userService;

private UserInfo userInfo;

public UserInfo getUserInfo() {
return userInfo;
} public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
} public UserService getUserService() {
return userService;
} public void setUserService(UserService userService) {
this.userService = userService;
}


public String execute() throws Exception {
return super.execute();
} public String regedit() throws Exception {

boolean flag = false;
System.out.println(userInfo);
System.out.println(this.userService);
flag = userService.insertUser(userInfo);
if(flag){
return "ok";
}else{
return "error";
}

}
}
userService对象为空

解决方案 »

  1.   

    你的dao方法列?还有异常信息!
      

  2.   

    userService不为空才怪
    <bean id="userService" class="com.soft.ssi.service.UserServiceImpl">
        <property name="userDao" ref="userDao"></property>
    </bean>
    spring管理的是UserServiceImpl,而你action里写的是private UserService userService,它又不归spring管理,spring无法给你注入,所以为空
      

  3.   


    userService是接口userServiceImpl是实现类
      

  4.   

    自动装配应该没有问题。
    是不是没有导入struts2-spring-plugin-xxx.jar包
      

  5.   

    就是报空指针错误嘛
    2010-7-1 17:25:26 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet default threw exception
    java.lang.NullPointerException
    at com.soft.ssi.web.UserAction.regedit(UserAction.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
    at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
      

  6.   

     at com.soft.ssi.web.UserAction.regedit(UserAction.java:39)这里报错了么 39行是哪行阿
      

  7.   

    页面上的userinfo是怎么样写的
      

  8.   

    flag = userService.insertUser(userInfo);
    这行报错 页面:<body>
        <s:form action="regedit" method="post">
         <s:textfield name="userInfo.username" label="用户名"></s:textfield><br>
         <s:password name="userInfo.password" label="密码"></s:password><br>
         <s:radio list="#{'1':'男','0':'女'}"  name="userInfo.sex" label="性别"></s:radio>
         <s:textfield name="userInfo.old" label="年龄"></s:textfield><br>
         <s:submit value="提交"></s:submit>
        </s:form>
      </body>
      

  9.   

    <bean id="UserAction" class="com.soft.ssi.web.UserAction">
        <property name="userService" ref="userService"></property>
    </bean>删了这个 试试看
      

  10.   

    我对struts不熟悉, 不过我认为是struts重新创建了一个UserAction对象,所以userService为null...
      

  11.   

    http://hi.baidu.com/softeem_lijie/blog/item/7702944298026e199213c651.html看看这例子吧...你的action配置了bean,strut调用时没去用,而是自己创建了实例,所以导致了userService为null
      

  12.   

    我觉得你也应该是忘记加了struts和spring整合的包,也就是4楼所说的struts2-spring-plugin-xxx.jar包
      

  13.   

    autowire="byName"
    装配模式你好象没写
      

  14.   

    UserAction 里的类并非注入的类
    后台有报错了么,如果没有报错应该是struts和spring的整合没有配置吧
      

  15.   


    <bean id="userDao" class="com.soft.ssi.dao.UserDaoImpl">
        <property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"></property>
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
      

  16.   

    <property name="sessionFactory" ref="sessionFactory"/>
      

  17.   

    4楼的说话有可能。在注入时。。ctrl+点击id名和ref名。看下偶到得了相应的位置不。。如果到得了 就有写错。。在看下有没有spring+struts的整合jar包。。多检查几遍我也弄了好久才弄出来
      

  18.   

    spring注入是基于接口的,所有spring管理的对象,都需要一个接口类和实现类