我用的myeclipse 9.0 + struts 2.1+spring 3.0 +hibernate 3.3
当我调试时得知, action bean UsersAction的usersService参数值总为空(action bean的接口参数总不能传入)? why?applicatonContext.xml内容:<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<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://127.0.0.1:1433;DatabaseName=testdb">
</property>
<property name="username" value="sa"></property>
<property name="password" value="123456"></property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/login/Users.hbm.xml</value></list>
</property></bean>

<bean id="UsersDAO" class="com.login.UsersDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<bean id="UsersService" class="com.login.UsersService">
 <property name="usersDAO" ref="UsersDAO" />
</bean><bean id="UsersAction" class="com.login.UsersAction">
 <property name="usersService" ref="UsersService" />
</bean><bean id="transactionManager"    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 <property name="sessionFactory">
 <ref bean="sessionFactory" />
 </property>
</bean><tx:advice id="txAdvice" transaction-manager="transactionManager">
 <tx:attributes>
 <tx:method name="save*" propagation="REQUIRED" />
 <tx:method name="update*" propagation="REQUIRED" />
 <tx:method name="delete*" propagation="REQUIRED" />
 <tx:method name="add*" propagation="REQUIRED" />
 <tx:method name="del*" propagation="REQUIRED" />
 <tx:method name="*" read-only="true" />
 </tx:attributes>
</tx:advice><aop:config>
 <aop:pointcut id="allServiceMethod" expression="execution(* app.service.*.*(..))" />
 <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config> </beans>当我调试时得知, bean UsersAction的usersService参数值总为空? why?
我上面的配置有什么问题? 

解决方案 »

  1.   

    你是交给spring处理的吗? 那你struts里面的action对应的class要和bean的id属性值一致,否则注入不成功。
      

  2.   

    楼主看看你struts2的配置文件里面的action配置
      

  3.   

    没报错吗?。setter方法设置个断点。看看有没进到方法里面去。如果配置文件写错的话应该会报错把?起码提示个反射创建找不到类什么的
      

  4.   

    +1像排查这种问题顺藤摸瓜比较好,bean与bean之间层层关联引用,通过调试找到哪一个环节没有初始化好
      

  5.   

    <bean id="UsersAction" class="com.login.UsersAction">
      <property name="usersService" ref="UsersService" />
     </bean>
    红色部分要和你在UsersAction中定义的名称一致
      

  6.   


    <aop:config>
     <aop:pointcut id="allServiceMethod" expression="execution(* app.service.*.*(..))" />
     <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
    </aop:config>楼主这个aop作用是?
      

  7.   

    建议LZ贴出action的代码,
    看看你的server是否注入,是用的setter注入,还是注解等。
      

  8.   

    谢谢大家, 是struts.xml 的action配置中package的命名问题,class最好是全称。
    jsp中form 的action 的问题。