开发者

scala+spring seems to ignore Qualifier annotation

开发者 https://www.devze.com 2023-02-21 02:01 出处:网络
I have something like this: class MyBean { @Autowired @Qualifier(\"jdbcTemplate\") @BeanProperty var jdbcTemplate : JdbcTemplate = null

I have something like this:

class MyBean {
    @Autowired
    @Qualifier("jdbcTemplate")
    @BeanProperty
    var jdbcTemplate : JdbcTemplate = null
}

Spring complains that it can't find a bean of type JdbcTemplate and refuses to autowire. My spring.xml has:

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
    <constructor-arg re开发者_C百科f="dataSource" />
</bean>

If I change the type of jdbcTemplate in MyBean from JdbcTemplate to SimpleJdbcTemplate then it works. My question is why is it apparently ignoring the Qualifier annotation? Am I doing something wrong?


It has nothing to do with @Qualifier. SimpleJdbcTemplate is not a subclass of JdbcTemplate, therefore it cannot be injected into a field of type JdbcTemplate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号