刚学注解,遇到问题,求解释
strut2的action里面:
[code=java]
@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;
[/code]
service里面:
[code=java]
@Service("iAcctUserService")
@Transactional
public class AcctUserService implements IAcctUserService{
@Autowired
private IAcctUserDao iAcctUserDao;
[/code]
dao里面:
[code=java]
@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;
}
[/code]
basedao:
[code=java]
public class BaseDao {
@Autowired
public JdbcTemplate jdbcTemplate;
[/code]
application.xml里面
XML code
<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总是为空
------解决方案--------------------application.xml 里面加上这句看看
<context:annotation-config/>
action中有iAcctUserService 的getter(),setter()方法吧
------解决方案--------------------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=iAcctUserSe