【发布时间】:2018-10-10 00:53:21
【问题描述】:
我有以下 RowMapper (ChallengeRowMapper) 实现,我试图在其中注入另一个 RowMapper (ClaimsViewRowMapper):
public class ChallengeRowMapper implements RowMapper<Challenge> {
@Autowired
@Qualifier("claimRowMapper1")
private ClaimsViewRowMapper clMapper;
.
.
@Override
public Challenge mapRow(ResultSet rs, int rowNum) throws SQLException {
LOGGER.debug("clMapper is:"+Boolean.toString(clMapper==null));//this prints true
Challenge c=(Challenge)clMapper.mapRow(rs, rowNum); //getting NPE here
}
}
@Autowired 由于某种原因无法正常工作,并且 clMapper 被设置为 NULL。 这是另一个被注释为@Component 的RowMapper。
@Component("claimRowMapper1")
public class ClaimsViewRowMapper implements RowMapper<Claim> {
}
这里要注意的另一点是挑战扩展声明。两个 rowMapper 都在同一个包中。并且这个包位于组件扫描路径下,因为包中的其他 DAO 与 Autowired 一起正常工作。 谁能解释一下为什么自动装配在这里不起作用?
【问题讨论】:
标签: java spring spring-boot autowired rowmapper