0

I have two database configuration javaconfig classes - one for JPA purposes with transactionManager() and entityManagerFactory() @Bean methods and one config class for non-JPA JDBCTemplate based query submission to access data from that database. The overall idea is to read using JDBCTemplate to read data and persist the data, after transformation, into the JPA based datasource. I am using Spring Boot to enable auto configuration. My test fails with:

    java.lang.IllegalArgumentException: Not an managed type: 

I have both spring-boot-starter-jdbc and spring-boot-starter-data-jpa in my build.gradle. My gut feeling is that the two data sources are in collision course with each other. How do I enforce the use of each of these datasources for the two use-cases that I mentioned earlier - one for JPA and another for JDBCTemplate purposes?

Details (Added after Dave's reply):

My service classes have been annotated with @Service and my repository classes have @Repository. Service uses repository objects using @Autowired though there are some services that are JDBCTemplate-based for data retrieval.

More complex depiction of my environment goes as follows (logically): JDBCTemplate(DataSource(Database(DB2)))--> Spring Batch Item Reader;Processors; Writer --> Service(Repository(JPADataSource(Database(H2)))). Spring batch item processors connect to both databases using services. For spring batch, I am using a H2 Job repo database (remote) to hold job execution details. Does this make sense? For Spring batch, I am using de.codecentric:spring-boot-starter-batch-web:1.0.0.RELEASE. After getting past the entityManagerFactory bean not found errors, I want to have control over the wiring of the above components.

1 Answer 1

1

I don't think it's anything to do with the data sources. The log says you have a JPA repository for a type that is not an @Entity. Repositories are automatically scanned from the package you define @EnableAutoConfiguration by default. So one way to control it is to move the class that has that annotation to a different package. In Boot 1.1 you can also set "spring.data.jpa.repositories.enabled=false" to switch off the scan if you don't want it. Or you can use @EnableJpaRepositories as normal.

Sign up to request clarification or add additional context in comments.

11 Comments

Unfortunately, when I try to switch off the scanning as suggested, I get nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type repository.
Without seeing all your code it's really impossible to interpret random one-line log statements. If you need a repository, why are you disabling them? Maybe you need to share a project.
I will add you to my github collaborators. What is your github user name?
I have added dsyer to my repo: github.com/naruraghavan/…
I can see the code. You have Spring Data repositories and entities, but I can see that you are manually configuring the LocalContainerEntityManagerFactoryBean (and a load of other things that Boot would do for you), and you are injecting a "entitymanager.packages.to.scan" that doesn't point to a package with any @Entity classes.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.