Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.36 KB | None | 0 0
  1. server:
  2. port: 9001
  3. contextPath: /ready
  4. spring:
  5. datasource:
  6. one:
  7. url: jdbc:mysql://localhost:3307/dummy
  8. driver-class-name: com.mysql.jdbc.Driver
  9. username: root
  10. password: root
  11. two:
  12. url: jdbc:mysql://localhost:3307/dummy_two
  13. driver-class-name: com.mysql.jdbc.Driver
  14. username: root
  15. password: root
  16.  
  17. ---
  18. spring:
  19. profiles: DEV
  20. spring.datasource:
  21. one:
  22. jndi-name: jdbc/myDBOne
  23. two:
  24. jndi-name: jdbc/myDBTwo
  25.  
  26. package com.springboot.web.config;
  27.  
  28. import javax.persistence.EntityManagerFactory;
  29. import javax.sql.DataSource;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.beans.factory.annotation.Qualifier;
  32. import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
  33. import org.springframework.boot.context.properties.ConfigurationProperties;
  34. import org.springframework.boot.context.properties.EnableConfigurationProperties;
  35. import org.springframework.context.annotation.Bean;
  36. import org.springframework.context.annotation.Configuration;
  37. import org.springframework.context.annotation.Primary;
  38. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  39. import org.springframework.orm.jpa.JpaTransactionManager;
  40. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  41. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  42. import org.springframework.transaction.PlatformTransactionManager;
  43. import org.springframework.transaction.annotation.EnableTransactionManagement;
  44.  
  45. /**
  46. *
  47. * @author amardeep2551
  48. */
  49. @Configuration
  50.  
  51. @EnableTransactionManagement
  52. @EnableJpaRepositories(
  53. entityManagerFactoryRef = "entityManagerFactoryOne",
  54. basePackages = { "com.springboot.web.repo.one" })
  55. public class JpaConfigOne {
  56.  
  57.  
  58.  
  59.  
  60.  
  61. @Primary
  62. @Bean(name = "entityManagerFactoryOne")
  63. @ConfigurationProperties(prefix = "spring.datasource.one")
  64. public LocalContainerEntityManagerFactoryBean entityManagerFactoryOne(
  65. DataSource dataSource
  66. ) {
  67.  
  68. LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
  69. lef.setPackagesToScan("com.springboot.web.domain.one");
  70. lef.setDataSource(dataSource);
  71. lef.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
  72.  
  73. return lef;
  74. }
  75.  
  76. @Primary
  77. @Bean(name = "transactionManager")
  78. public PlatformTransactionManager transactionManager(
  79. @Qualifier("entityManagerFactoryOne") EntityManagerFactory entityManagerFactoryOne) {
  80. return new JpaTransactionManager(entityManagerFactoryOne);
  81. }
  82. }
  83.  
  84. /*
  85. * To change this license header, choose License Headers in Project Properties.
  86. * To change this template file, choose Tools | Templates
  87. * and open the template in the editor.
  88. */
  89. package com.springboot.web.config;
  90.  
  91. import javax.persistence.EntityManagerFactory;
  92. import javax.sql.DataSource;
  93. import org.springframework.beans.factory.annotation.Autowired;
  94. import org.springframework.beans.factory.annotation.Qualifier;
  95. import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
  96. import org.springframework.boot.context.properties.ConfigurationProperties;
  97. import org.springframework.context.annotation.Bean;
  98. import org.springframework.context.annotation.Configuration;
  99. import org.springframework.context.annotation.Primary;
  100. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  101. import org.springframework.orm.jpa.JpaTransactionManager;
  102. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  103. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  104. import org.springframework.transaction.PlatformTransactionManager;
  105. import org.springframework.transaction.annotation.EnableTransactionManagement;
  106.  
  107. /**
  108. *
  109. * @author amardeep2551
  110. */
  111. @Configuration
  112. @EnableTransactionManagement
  113. @EnableJpaRepositories(
  114. entityManagerFactoryRef = "entityManagerFactoryTwo",
  115. basePackages = { "com.springboot.web.repo.two" })
  116. public class JpaConfigTwo {
  117.  
  118.  
  119.  
  120. @Bean(name = "entityManagerFactoryTwo")
  121. @ConfigurationProperties(prefix = "spring.datasource.two")
  122. public LocalContainerEntityManagerFactoryBean entityManagerFactory(
  123. DataSource dataSource
  124. ) {
  125.  
  126. LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
  127. lef.setPackagesToScan("com.springboot.web.domain.two");
  128. lef.setDataSource(dataSource);
  129. lef.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
  130.  
  131. return lef;
  132. }
  133.  
  134. @Primary
  135. @Bean(name = "transactionManager")
  136. public PlatformTransactionManager transactionManager(
  137. @Qualifier("entityManagerFactoryTwo") EntityManagerFactory entityManagerFactory) {
  138. return new JpaTransactionManager(entityManagerFactory);
  139. }
  140. }
  141.  
  142. /*
  143. * To change this license header, choose License Headers in Project Properties.
  144. * To change this template file, choose Tools | Templates
  145. * and open the template in the editor.
  146. */
  147. package com.springboot.web;
  148.  
  149. import org.springframework.boot.SpringApplication;
  150. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  151. import org.springframework.boot.autoconfigure.SpringBootApplication;
  152. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  153. import org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration;
  154. import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
  155. import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
  156. import org.springframework.boot.context.web.SpringBootServletInitializer;
  157.  
  158. /**
  159. *
  160. * @author amardeep2551
  161. */
  162. @EnableAutoConfiguration
  163. @SpringBootApplication()
  164. public class Application extends SpringBootServletInitializer{
  165. public static void main(String[] args) {
  166.  
  167. SpringApplication.run(Application.class, args);
  168. }
  169. }
  170.  
  171. <?xml version="1.0" encoding="UTF-8"?>
  172. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  173. <modelVersion>4.0.0</modelVersion>
  174. <parent>
  175. <groupId>org.springframework.boot</groupId>
  176. <artifactId>spring-boot-starter-parent</artifactId>
  177. <version>1.3.1.RELEASE</version>
  178. <relativePath /> <!-- lookup parent from repository -->
  179. </parent>
  180.  
  181. <groupId>com.springboot.web</groupId>
  182. <artifactId>SpringBootWeb</artifactId>
  183. <version>1.0-SNAPSHOT</version>
  184. <packaging>war</packaging>
  185.  
  186. <name>SpringBootWeb</name>
  187.  
  188. <properties>
  189. <java.version>1.8</java.version>
  190. <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
  191. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  192. </properties>
  193.  
  194. <dependencies>
  195.  
  196.  
  197. <dependency>
  198. <groupId>org.springframework.boot</groupId>
  199. <artifactId>spring-boot-starter-web</artifactId>
  200. </dependency>
  201. <dependency>
  202. <groupId>org.springframework.boot</groupId>
  203. <artifactId>spring-boot-starter-data-jpa</artifactId>
  204. </dependency>
  205. <dependency>
  206. <groupId>org.projectlombok</groupId>
  207. <artifactId>lombok</artifactId>
  208. <version>1.14.4</version>
  209. <scope>provided</scope>
  210. </dependency>
  211. <dependency>
  212. <groupId>mysql</groupId>
  213. <artifactId>mysql-connector-java</artifactId>
  214. </dependency>
  215. <dependency>
  216. <groupId>javax</groupId>
  217. <artifactId>javaee-web-api</artifactId>
  218. <version>6.0</version>
  219. <scope>provided</scope>
  220. </dependency>
  221. </dependencies>
  222.  
  223. <build>
  224. <resources>
  225. <resource>
  226. <directory>src/main/resources</directory>
  227. </resource>
  228. </resources>
  229. <plugins>
  230.  
  231. <plugin>
  232. <groupId>org.apache.maven.plugins</groupId>
  233. <artifactId>maven-compiler-plugin</artifactId>
  234. <version>2.3.2</version>
  235. <configuration>
  236. <source>1.6</source>
  237. <target>1.6</target>
  238. <compilerArguments>
  239. <endorseddirs>${endorsed.dir}</endorseddirs>
  240. </compilerArguments>
  241. </configuration>
  242. </plugin>
  243. <plugin>
  244. <groupId>org.apache.maven.plugins</groupId>
  245. <artifactId>maven-war-plugin</artifactId>
  246. <version>2.1.1</version>
  247. <configuration>
  248. <failOnMissingWebXml>false</failOnMissingWebXml>
  249. </configuration>
  250. </plugin>
  251. <plugin>
  252. <groupId>org.apache.maven.plugins</groupId>
  253. <artifactId>maven-dependency-plugin</artifactId>
  254. <version>2.1</version>
  255. <executions>
  256. <execution>
  257. <phase>validate</phase>
  258. <goals>
  259. <goal>copy</goal>
  260. </goals>
  261. <configuration>
  262. <outputDirectory>${endorsed.dir}</outputDirectory>
  263. <silent>true</silent>
  264. <artifactItems>
  265. <artifactItem>
  266. <groupId>javax</groupId>
  267. <artifactId>javaee-endorsed-api</artifactId>
  268. <version>6.0</version>
  269. <type>jar</type>
  270. </artifactItem>
  271. </artifactItems>
  272. </configuration>
  273. </execution>
  274. </executions>
  275. </plugin>
  276.  
  277. </plugins>
  278. </build>
  279. <repositories>
  280.  
  281. <repository>
  282. <id>projectlombok.org</id>
  283. <name>Lombok Repository</name>
  284. <url>http://projectlombok.org/mavenrepo</url>
  285. </repository>
  286. </repositories>
  287. </project>
  288.  
  289. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryOne' defined in class path resource [com/springboot/web/config/JpaConfigOne.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [javax.sql.DataSource]: : Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
  290. at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  291. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  292. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  293. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  294. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  295. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  296. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  297. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  298. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  299. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  300. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  301. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  302. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
  303. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
  304. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
  305. at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
  306. at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
  307. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
  308. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
  309. at com.springboot.web.Application.main(Application.java:26) [classes/:na]
  310.  
  311. @Primary
  312. @Bean(name = "entityManagerFactoryOne")
  313. @ConfigurationProperties(prefix = "spring.datasource.one")
  314. public LocalContainerEntityManagerFactoryBean entityManagerFactoryOne(
  315. DataSource dataSource
  316. ) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement