I have this repository:
@Repository
public class MyRepository {
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public MyRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}
void doSomething() {
namedParameterJdbcTemplate.update(...);
}
}
Which worked as expected with Spring Boot 1.4.5 (Spring Core & JDBC 4.3.7). When debugging doSomething()
, I can see that the instance of MyRepository
is an ordinary object and the namedParameterJdbcTemplate
is set.
However, as soon as I update to Spring Boot 1.4.6 (Spring Core & JDBC 4.3.8) or higher, the instance of MyRepository
is a MyRepository$$EnhancerBySpringCGLIB
and namedParameterJdbcTemplate
is null
. I see it being injected in the constructor, however, at that point my repository is not yet CGLIB enhanced.
Why is that? I couldn't find a hint in the release 4.3.8 release notes.
I had something related. My methods were final and because of this, Spring was using CGLIB Proxied Classes instead of the default behavior (Spring AOP Proxied Classes). So to access the class properties, I had to call the getXXX() method, otherwise, the property would be returned null every time I've tried to access it.
I had a similar problem... I fixed my case by changing method to public instead of protected.
Have you tried
@Repository
public class MyRepository {
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public MyRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}
public void doSomething() {
namedParameterJdbcTemplate.update(...);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With