0
votes

My application is using Spring Boot (latest version) and has a dependency which uses Spring (latest version). The dependency has a Dao class annotated with @Repository that extends a couple of unannotated abstract classes up to JdbcDaoSupport. Moreover, this class has a @PostConstruct-annotated method, that sets the datasource.

A secondary Service class, annotated with @Service, extends from Dao.

I'm finding that an autowired <Service instance>.getJdbcTemplate() - which comes from the above-mentioned JdbcDaoSupport superclass - gives null.

If I omit the @Repository annotation on Dao, the jdbcTtemplate is correctly set. The same happens if I annotate that Dao with @Service.

A part from the fact that I may have annotated them both for no specific purposes - the whole application code is experimental, though I can see a situation where the main service extends the repository (dao) while a more complex one can implement its logic delegating to several dao's - is this forbidden by Spring or am I missing something?

UPDATE

I added a @PostConstruct method to the service and it's not being called.

UPDATE / 2

I tried autowiring the dao inside the service, but I get the same result; it seems to me a matter of @Repository and PersistenceExceptionTranslationPostProcessor where the latter replaces my bean with a proxy-generated one (GitHub issue).

1

1 Answers

0
votes

You should Autowire DAO into Service instead of extend.