strut2的action里面:@Namespace("/acctuser")
@Results( { @Result(name = CrudActionSupport.OK, location = "acctuser",type="chain") })
@Component("acctuser")
@Scope("prototype")
@SuppressWarnings("serial")
public class AcctuserAction extends CrudActionSupport<AcctUser> { @Autowired
private IAcctUserService iAcctUserService;service里面:@Service("iAcctUserService")
@Transactional
public class AcctUserService implements IAcctUserService{

@Autowired
private IAcctUserDao iAcctUserDao;dao里面:@Repository("iAcctUserDao")
public class AcctUserDao extends BaseDao implements IAcctUserDao{ public boolean login(String uname, String upass) {
String sql = "select count(*) from acct_user where login_name='"
+ uname + "' and password='" + upass + "'";
int count=jdbcTemplate.queryForInt(sql);
if(count>0){
return true;
}
return false;
}basedao:public class BaseDao {
@Autowired
public JdbcTemplate jdbcTemplate;application.xml里面<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath*:/util.properties</value>
</list>
</property>
</bean> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.jw" /> <!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${mysql.driver}" />
<property name="url" value="${mysql.url}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.password}"></property>
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven proxy-target-class="true" /> <bean name="jdbcTemplet" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
action里面的那个iAcctUserService总是为空

解决方案 »

  1.   

    xml头文件中加入 default-autowire="byName" 
      

  2.   

    application.xml 里面加上这句看看<context:annotation-config/> action中有iAcctUserService 的getter(),setter()方法吧
      

  3.   

    application.xml 里面加上这句看看<context:annotation-config/>  
    action中@Autowired 
    private IAcctUserService iAcctUserService; 改成:
    private IAcctUserService iAcctUserService; public  IAcctUserService getIAcctUserService(){
            return iAcctUserService;
    }@Autowired 
    public  IAcctUserService setIAcctUserService(IAcctUserService iAcctUserService){
            this.iAcctUserService=iAcctUserService;
    }