Skip to content

Commit c73ab2a

Browse files
author
Sahir
committed
add multiple data jpa tutorial
1 parent 90f017d commit c73ab2a

File tree

12 files changed

+649
-0
lines changed

12 files changed

+649
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ gradlew
5858
gradlew.bat
5959
gradle
6060
gradlew*
61+
62+
#application configuration
63+
application-*.yml

build.gradle

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
ext {
2+
//spring libs
3+
springVersion = '5.0.2.RELEASE'
4+
bootVersion = '2.0.0.M7'
5+
springDataVersion = '2.0.2.RELEASE'
6+
springAmqpVersion = '2.0.2.RELEASE'
7+
springSecurityVersion = '5.0.0.RELEASE'
8+
springBatchVersion = '4.0.0.RELEASE'
9+
springIntegrationVersion = '5.0.0.RELEASE'
10+
springBatchIntegrationVersion = '4.0.0.RELEASE'
11+
12+
//logging libs
13+
slf4jVersion = '1.7.25'
14+
logbackVersion = '1.2.3'
15+
16+
groovyVersion = '2.4.5'
17+
guavaVersion = '21.0'
18+
19+
aspectjVersion = '1.9.0.BETA-5'
20+
derbyVersion = '10.13.1.1'
21+
dbcpVersion = '2.1'
22+
mysqlVersion = '6.0.6'
23+
h2Version = '1.4.194'
24+
jodaVersion = '2.9.9'
25+
utVersion = '6.0.1.GA'
26+
javaxValidationVersion = '2.0.0.Beta2'
27+
javaElVersion = '3.0.1-b04'
28+
glasshfishELVersion = '2.2.1-b05'
29+
jmsVersion = '2.0'
30+
artemisVersion = '2.1.0'
31+
hornetqVersion = '2.4.0.Final'
32+
castorVersion = '1.4.1'
33+
jacksonVersion = '2.9.0'
34+
httpclientVersion = '4.5.3'
35+
poiVersion = '3.16'
36+
tilesVersion = '3.0.7'
37+
bootstrapVersion = '3.3.7-1'
38+
thymeSecurityVersion = '3.0.2.RELEASE'
39+
jQueryVersion = '3.2.1'
40+
twsVersion = '9.0.0.M22'
41+
42+
//persistency libraries
43+
hibernateVersion = '5.2.10.Final'
44+
hibernateJpaVersion = '1.0.0.Final'
45+
hibernateValidatorVersion = '5.4.1.Final' //6.0.0.Beta2
46+
atomikosVersion = '4.0.4'
47+
48+
//testing libs
49+
mockitoVersion = '2.0.2-beta'
50+
junitVersion = '4.12'
51+
hamcrestVersion = '1.3'
52+
dbunitVersion = '2.5.3'
53+
junit5Version = '5.0.0-M4'
54+
55+
spring = [
56+
context : "org.springframework:spring-context:$springVersion",
57+
webmvc : "org.springframework:spring-webmvc:$springVersion",
58+
aop : "org.springframework:spring-aop:$springVersion",
59+
aspects : "org.springframework:spring-aspects:$springVersion",
60+
tx : "org.springframework:spring-tx:$springVersion",
61+
jdbc : "org.springframework:spring-jdbc:$springVersion",
62+
contextSupport : "org.springframework:spring-context-support:$springVersion",
63+
orm : "org.springframework:spring-orm:$springVersion",
64+
data : "org.springframework.data:spring-data-jpa:$springDataVersion",
65+
test : "org.springframework:spring-test:$springVersion",
66+
jms : "org.springframework:spring-jms:$springVersion",
67+
oxm : "org.springframework:spring-oxm:$springVersion",
68+
securityWeb : "org.springframework.security:spring-security-web:$springSecurityVersion",
69+
securityConfig : "org.springframework.security:spring-security-config:$springSecurityVersion",
70+
securityTaglibs : "org.springframework.security:spring-security-taglibs:$springSecurityVersion",
71+
rabbit : "org.springframework.amqp:spring-rabbit:$springAmqpVersion",
72+
springSecurityTest: "org.springframework.security:spring-security-test:$springSecurityVersion",
73+
webSocket : "org.springframework:spring-websocket:$springVersion",
74+
messaging : "org.springframework:spring-messaging:$springVersion",
75+
batchCore : "org.springframework.batch:spring-batch-core:$springBatchVersion",
76+
batchIntegration : "org.springframework.batch:spring-batch-integration:$springBatchIntegrationVersion",
77+
integrationFile : "org.springframework.integration:spring-integration-file:$springIntegrationVersion",
78+
webflux : "org.springframework:spring-webflux:$springVersion"
79+
80+
]
81+
82+
hibernate = [
83+
validator : "org.hibernate:hibernate-validator:$hibernateValidatorVersion",
84+
jpaModelGen: "org.hibernate:hibernate-jpamodelgen:$hibernateVersion",
85+
ehcache : "org.hibernate:hibernate-ehcache:$hibernateVersion",
86+
em : "org.hibernate:hibernate-entitymanager:$hibernateVersion",
87+
envers : "org.hibernate:hibernate-envers:$hibernateVersion",
88+
jpaApi : "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:$hibernateJpaVersion",
89+
querydslapt: "com.mysema.querydsl:querydsl-apt:2.7.1",
90+
tx : "com.atomikos:transactions-hibernate4:$atomikosVersion"
91+
]
92+
93+
94+
boot = [
95+
springBootPlugin: "org.springframework.boot:spring-boot-gradle-plugin:$bootVersion",
96+
starter : "org.springframework.boot:spring-boot-starter:$bootVersion",
97+
starterWeb : "org.springframework.boot:spring-boot-starter-web:$bootVersion",
98+
actuator : "org.springframework.boot:spring-boot-starter-actuator:$bootVersion",
99+
starterTest : "org.springframework.boot:spring-boot-starter-test:$bootVersion",
100+
starterAop : "org.springframework.boot:spring-boot-starter-aop:$bootVersion",
101+
starterJdbc : "org.springframework.boot:spring-boot-starter-jdbc:$bootVersion",
102+
starterJpa : "org.springframework.boot:spring-boot-starter-data-jpa:$bootVersion",
103+
starterJta : "org.springframework.boot:spring-boot-starter-jta-atomikos:$bootVersion",
104+
starterJms : "org.springframework.boot:spring-boot-starter-artemis:$bootVersion",
105+
starterRabbitmq : "org.springframework.boot:spring-boot-starter-amqp:$bootVersion",
106+
starterThyme : "org.springframework.boot:spring-boot-starter-thymeleaf:$bootVersion",
107+
starterSecurity : "org.springframework.boot:spring-boot-starter-security:$bootVersion",
108+
starterBatch : "org.springframework.boot:spring-boot-starter-batch:$bootVersion",
109+
starterWebflux : "org.springframework.boot:spring-boot-starter-webflux:$bootVersion"
110+
111+
]
112+
113+
testing = [
114+
junit : "junit:junit:$junitVersion",
115+
junit5Engine: "org.junit.jupiter:junit-jupiter-engine:$junit5Version",
116+
junit5Runner: "org.junit.platform:junit-platform-runner:1.0.0-M4",
117+
mockito : "org.mockito:mockito-all:$mockitoVersion",
118+
easymock : "org.easymock:easymock:3.4",
119+
jmock : "org.jmock:jmock:2.8.2",
120+
hamcrestCore: "org.hamcrest:hamcrest-core:$hamcrestVersion",
121+
hamcrestLib : "org.hamcrest:hamcrest-library:$hamcrestVersion",
122+
dbunit : "org.dbunit:dbunit:$dbunitVersion"
123+
]
124+
125+
126+
misc = [
127+
slf4jJcl : "org.slf4j:jcl-over-slf4j:$slf4jVersion",
128+
logback : "ch.qos.logback:logback-classic:$logbackVersion",
129+
groovy : "org.codehaus.groovy:groovy-all:$groovyVersion",
130+
inject : "javax.inject:javax.inject:1",
131+
validation : "javax.validation:validation-api:$javaxValidationVersion",
132+
aspectjweaver : "org.aspectj:aspectjweaver:$aspectjVersion",
133+
aspectjrt : "org.aspectj:aspectjrt:$aspectjVersion",
134+
lang3 : "org.apache.commons:commons-lang3:3.5",
135+
guava : "com.google.guava:guava:$guavaVersion",
136+
joda : "joda-time:joda-time:$jodaVersion",
137+
usertype : "org.jadira.usertype:usertype.core:$utVersion",
138+
artemis : "org.apache.activemq:artemis-jms-server:2.1.0",
139+
javaEl : "javax.el:javax.el-api:$javaElVersion",
140+
glassfishEl : "org.glassfish.web:el-impl:$glasshfishELVersion",
141+
jms : "javax.jms:javax.jms-api:$jmsVersion",
142+
artemisClient : "org.apache.activemq:artemis-jms-client:$artemisVersion",
143+
artemisServer : "org.apache.activemq:artemis-jms-server:$artemisVersion",
144+
hornetq : "org.hornetq:hornetq-jms-client:$hornetqVersion",
145+
castor : "org.codehaus.castor:castor-xml:$castorVersion",
146+
jacksonDatabind: "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
147+
poi : "org.apache.poi:poi:$poiVersion",
148+
io : "commons-io:commons-io:2.5",
149+
]
150+
151+
web = [
152+
tiles : "org.apache.tiles:tiles-jsp:$tilesVersion",
153+
jstl : "jstl:jstl:1.2",
154+
bootstrap : "org.webjars:bootstrap:$bootstrapVersion",
155+
jQuery : "org.webjars:jquery:$jQueryVersion",
156+
thymeSecurity: "org.thymeleaf.extras:thymeleaf-extras-springsecurity4:$thymeSecurityVersion",
157+
tomcatWsApi : "org.apache.tomcat:tomcat-websocket-api:$twsVersion",
158+
tomcatWsEmbed: "org.apache.tomcat.embed:tomcat-embed-websocket:$twsVersion",
159+
httpclient : "org.apache.httpcomponents:httpclient:$httpclientVersion",
160+
websocket : "javax.websocket:javax.websocket-api:1.1",
161+
servlet : "javax.servlet:javax.servlet-api:3.1.0",
162+
]
163+
164+
react = [
165+
projReactorIpc: "io.projectreactor.ipc:reactor-netty:0.7.0.M1",
166+
tomcatEmbedded: "org.apache.tomcat.embed:tomcat-embed-core:9.0.0.M25",
167+
]
168+
169+
db = [
170+
mysql : "mysql:mysql-connector-java:$mysqlVersion",
171+
derby : "org.apache.derby:derby:$derbyVersion",
172+
dbcp2 : "org.apache.commons:commons-dbcp2:$dbcpVersion",
173+
dbcp : "commons-dbcp:commons-dbcp:1.4",
174+
h2 : "com.h2database:h2:$h2Version",
175+
hsqldb: "org.hsqldb:hsqldb:2.4.0"
176+
]
177+
}
178+
179+
subprojects {
180+
version '1.0.0'
181+
182+
repositories {
183+
mavenLocal()
184+
mavenCentral()
185+
maven { url "http://repo.spring.io/release" }
186+
maven { url "http://repo.spring.io/snapshot" }
187+
maven { url "https://repo.spring.io/libs-snapshot" }
188+
maven { url "http://repo.spring.io/milestone" }
189+
maven { url "https://repo.spring.io/libs-milestone" }
190+
}
191+
}
192+
193+
tasks.withType(JavaCompile) {
194+
options.encoding = "UTF-8"
195+
}
196+
197+
task wrapper(type: Wrapper) {
198+
gradleVersion = '4.0'
199+
}

settings.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
rootProject.name = 'spring-boot-tutorial'
2+
3+
include 'spring-boot-data'
4+
include 'spring-boot-data:spring-boot-data-jpa-multiple'
5+
findProject(':spring-boot-data:spring-boot-data-jpa-multiple')?.name = 'spring-boot-data-jpa-multiple'
6+
7+
include 'spring-boot-mvc'
8+
9+
10+
11+
//we check if the modules have gradle configuration files
12+
rootProject.children.each { project ->
13+
project.buildFileName = "${project.name}.gradle"
14+
assert project.projectDir.isDirectory()
15+
assert project.buildFile.exists()
16+
assert project.buildFile.isFile()
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
mavenCentral()
5+
maven { url "http://repo.spring.io/release" }
6+
maven { url "http://repo.spring.io/snapshot" }
7+
maven { url "https://repo.spring.io/libs-snapshot" }
8+
maven { url "http://repo.spring.io/milestone" }
9+
maven { url "https://repo.spring.io/libs-milestone" }
10+
}
11+
12+
dependencies {
13+
classpath boot.springBootPlugin
14+
}
15+
}
16+
17+
apply plugin: 'org.springframework.boot'
18+
19+
dependencies {
20+
compile boot.starterJpa, db.mysql
21+
}
22+
23+
jar {
24+
manifest {
25+
attributes("Created-By": "Iuliana Cosmina",
26+
"Specification-Title": "Pro Spring 5",
27+
"Main-Class" : "id.web.sahir.tutorial.springboot.data.jpa.multiple.SpringBootDataMultipleApplication",
28+
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
2+
hikari.addDataSourceProperty("serverName", getConfig().getString("mysql.ip"));
3+
hikari.addDataSourceProperty("port", getConfig().getString("mysql.port"));
4+
hikari.addDataSourceProperty("databaseName", getConfig().getString("mysql.database"));
5+
hikari.addDataSourceProperty("user", getConfig().getString("mysql.username"));
6+
hikari.addDataSourceProperty("password", getConfig().getString("mysql.password"));
7+
8+
9+
spring.datasource.url=jdbc:mysql://localhost:3306/database
10+
spring.datasource.username=root
11+
spring.datasource.password=Password1
12+
spring.datasource.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
13+
14+
spring.jpa.hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider
15+
spring.jpa.hibernate.hikari.minimumIdle=5
16+
spring.jpa.hibernate.hikari.maximumPoolSize=10
17+
spring.jpa.hibernate.hikari.idleTimeout=30000
18+
19+
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
20+
spring.jpa.properties.hibernate.show_sql=false
21+
spring.jpa.properties.hibernate.hbm2ddl.auto=update
22+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
23+
spring.jpa.properties.hibernate.cache.use_query_cache=true
24+
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
25+
spring.jpa.properties.hibernate.cache.default_cache_concurrency_strategy=READ_WRITE
26+
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
27+
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
28+
29+
# Reference
30+
- http://www.baeldung.com/spring-boot-custom-auto-configuration
31+
- https://stackoverflow.com/questions/28821521/configure-datasource-programmatically-in-spring-boot
32+
- http://www.baeldung.com/spring-data-jpa-multiple-databases
33+
- https://github.com/webjars/sample-jetty_war
34+
- https://www.webjars.org/documentation#springmvc
35+
- https://www.ccampo.me/java/spring/2016/02/13/multi-datasource-spring-boot.html
36+
- https://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-one-configuration/
37+
- https://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-two-crud/
38+
- http://www.springboottutorial.com/spring-boot-auto-configuration
39+
- https://github.com/snicoll-demos/demo-multi-entity-managers
40+
- https://www.ccampo.me/java/spring/2016/02/13/multi-datasource-spring-boot.html
41+
- https://medium.com/@joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7
42+
- https://github.com/jahe/spring-boot-multiple-datasources
43+
- http://roufid.com/spring-boot-multiple-databases-configuration/
44+
- https://www.callicoder.com/spring-boot-rest-api-tutorial-with-mysql-jpa-hibernate/
45+
- http://www.baeldung.com/spring-data-jpa-multiple-databases
46+
47+
48+
# Reference Transaction Management
49+
- http://www.codingpedia.org/jhadesdev/how-does-spring-transactional-really-work/
50+
- https://spring.io/guides/gs/managing-transactions/
51+
- https://dzone.com/articles/spring-transaction-management
52+
- https://www.ibm.com/developerworks/library/j-ts1/index.html
53+
- https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html
54+
- http://www.mkyong.com/spring/spring-aop-transaction-management-in-hibernate/
55+
- http://www.baeldung.com/transaction-configuration-with-jpa-and-spring
56+
- http://www.logicbig.com/tutorials/spring-framework/spring-data-access-with-jdbc/transactional-annotation/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package id.web.sahir.tutorial.springboot.data.jpa.multiple;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
8+
import org.springframework.transaction.annotation.EnableTransactionManagement;
9+
10+
//@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
11+
@SpringBootApplication
12+
public class SpringBootDataMultipleApplication {
13+
final static private Logger logger = LoggerFactory.getLogger(SpringBootDataMultipleApplication.class);
14+
15+
public static void main(String[] args) {
16+
SpringApplication.run(SpringBootDataMultipleApplication.class, args);
17+
}
18+
}

0 commit comments

Comments
 (0)