在RowMapper实现中自动连线设置为空

时间:2018-10-10 00:53:22

标签: java spring spring-boot autowired rowmapper

我有以下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。 这是另一个RowMapper,其注释为@Component。

@Component("claimRowMapper1")
public class ClaimsViewRowMapper implements RowMapper<Claim> {
}

这里要注意的另一点是“挑战扩展索赔”。两个rowMappers都在同一包中。并且此软件包位于组件扫描路径下,因为该软件包中的其他DAO可以与Autowired一起正常使用。 谁能解释一下为什么自动布线在这里不起作用?

1 个答案:

答案 0 :(得分:0)

您是否用@Component注释了ChallengeRowMapper类?