Is it possible to use to use MS Sql
and Hibernate
entityManagerFactory with DAO's in Spring XD??
I have a Configuration Class in my project in which I am writing Beans necessary for required configurations for my project like my DataSource
and JDBCTemplate
.
I also have Beans like
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("sqlServerDataSource") DataSource dataSource) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter());
lef.setPackagesToScan("de.id.dih");
return lef;
}
private JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(true);
hibernateJpaVendorAdapter.setDatabase(Database.SQL_SERVER);
return hibernateJpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager(LocalContainerEntityManagerFactoryBean emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf.getObject());
return transactionManager;
}
When I deploy my project in Spring XD,
I get Exception :
java.lang.NoClassDefFoundError: org/springframework/orm/jpa/JpaVendorAdapter.
Then, I added the dependancy for spring-boot-starter-data-jpa, I got exception like
java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
I tried to include dependancy for Spring Boot with and without Scope provided. I even tried adding dependancies for
hibernate-jpa-2.1-api,
hibernate-entitymanager,
spring-orm
to local POM.
I also moved the dependencies directly to Spring XD lib folder, and after doing that I got exception:
ERROR main boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set .
And when I set the hibernate.dialect my exception looks like:
16:39:23,344 ERROR DeploymentsPathChildrenCache-0 server.ContainerRegistrar - Exception deploying module java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:381) at org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:352) at org.springframework.boot.SpringApplication.run(SpringApplication.java:274) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142) at org.springframework.xd.module.core.SimpleModule.initialize(SimpleModule.java:203) at org.springframework.xd.dirt.module.ModuleDeployer.deploy(ModuleDeployer.java:98) at org.springframework.xd.dirt.module.ModuleDeployer.deployAndStore(ModuleDeployer.java:88) at org.springframework.xd.dirt.module.ModuleDeployer.deployAndStore(ModuleDeployer.java:78) at org.springframework.xd.dirt.server.ContainerRegistrar.deployModule(ContainerRegistrar.java:231) at org.springframework.xd.dirt.server.ContainerRegistrar.deployJobModule(ContainerRegistrar.java:530) at org.springframework.xd.dirt.server.ContainerRegistrar.onChildAdded(ContainerRegistrar.java:447) at org.springframework.xd.dirt.server.ContainerRegistrar.access$800(ContainerRegistrar.java:95) at org.springframework.xd.dirt.server.ContainerRegistrar$DeploymentListener.childEvent(ContainerRegistrar.java:826) at org.apache.curator.framework.recipes.cache.PathChildrenCache$5.apply(PathChildrenCache.java:509) at org.apache.curator.framework.recipes.cache.PathChildrenCache$5.apply(PathChildrenCache.java:503) at org.apache.curator.framework.listen.ListenerContainer$1.run(ListenerContainer.java:92) at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297) at org.apache.curator.framework.listen.ListenerContainer.forEach(ListenerContainer.java:83) at org.apache.curator.framework.recipes.cache.PathChildrenCache.callListeners(PathChildrenCache.java:500) at org.apache.curator.framework.recipes.cache.EventOperation.invoke(EventOperation.java:35) at org.apache.curator.framework.recipes.cache.PathChildrenCache$10.run(PathChildrenCache.java:762) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.IllegalArgumentException: class org.springframework.boot.context.event.EventPublishingRunListener is not assignable to interface org.springframework.boot.SpringApplicationRunListener at org.springframework.util.Assert.isAssignable(Assert.java:369) at org.springframework.util.Assert.isAssignable(Assert.java:352) at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:375) ... 29 more
Does any body have an idea of what might be causing this Exception ?
HELP REGARDING WORKING EXAMPLE OF THE ABOVE WITH SPRING-XD IS GREATLY APPRECIATED.
Thanks