【问题标题】:Autowired in a RowMapper implementation sets null在 RowMapper 实现中自动装配设置为 null
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 你能告诉我注释 ChallengeRowMapper 有什么需要吗?我只需要注入 ClaimsViewRowMapper。
    猜你喜欢
    • 2020-04-09
    • 2012-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-08
    • 2015-11-22
    • 1970-01-01
    相关资源
    最近更新 更多