Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit e6882c6

Browse files
committed
chore: Cleanup examples-spring-boot-hibernate5
- `application.yml`: Format properly with 2 spaces remove unused config. - `Application`: Exclude `HibernateJpaAutoConfiguration` to avoid duplicate transaction managers: java.lang.ClassCastException: class org.springframework.orm.jpa.EntityManagerHolder cannot be cast to class org.springframework.orm.hibernate5.SessionHolder (org.springframework.orm.jpa.EntityManagerHolder and org.springframework.orm.hibernate5.SessionHolder are in unnamed module of loader 'app') - `BookController`: Add `@ReadOnly` to `books()` action to get a session for the `Book.list()` method. - `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied. Add version variable `springBootGradlePluginVersion`.
1 parent 23c42a4 commit e6882c6

File tree

5 files changed

+26
-33
lines changed

5 files changed

+26
-33
lines changed
Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,28 @@
1-
21
buildscript {
32
repositories {
43
mavenCentral()
54
}
65
dependencies {
7-
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.3.5")
6+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootGradlePluginVersion"
87
}
98
}
109

11-
apply plugin: 'java'
10+
apply plugin: 'groovy'
1211
apply plugin: 'org.springframework.boot'
13-
apply plugin: "groovy"
1412

15-
group 'examples'
13+
version = rootProject.version
14+
group = 'examples'
1615

1716
dependencies {
18-
implementation platform("org.grails:grails-bom:$grailsVersion")
19-
implementation("org.springframework.boot:spring-boot-starter")
20-
implementation("org.springframework.boot:spring-boot-starter-web")
21-
implementation "org.springframework.boot:spring-boot-autoconfigure"
22-
implementation "org.springframework.boot:spring-boot-starter-tomcat"
23-
implementation project(":gorm-hibernate5-spring-boot")
24-
implementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
25-
implementation "org.hibernate:hibernate-ehcache:$hibernateVersion"
26-
27-
runtimeOnly "com.h2database:h2"
28-
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
29-
runtimeOnly "org.apache.tomcat.embed:tomcat-embed-logging-log4j:$tomcatLog4jVersion"
30-
runtimeOnly "org.slf4j:slf4j-api"
3117

32-
testImplementation "org.spockframework:spock-core"
18+
implementation project(':gorm-hibernate5-spring-boot')
19+
implementation 'org.springframework.boot:spring-boot-starter-web'
3320

34-
testRuntimeOnly "org.slf4j:slf4j-simple"
21+
runtimeOnly 'com.h2database:h2'
22+
runtimeOnly 'com.zaxxer:HikariCP'
23+
runtimeOnly 'org.springframework.boot:spring-boot-autoconfigure'
24+
runtimeOnly 'org.springframework.boot:spring-boot-starter-logging'
25+
runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'
3526

36-
testImplementation('org.springframework.boot:spring-boot-starter-test')
27+
testImplementation 'org.spockframework:spock-core'
3728
}

examples/spring-boot-hibernate5/src/main/groovy/example/Application.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import groovy.transform.CompileStatic
55
import org.springframework.boot.CommandLineRunner
66
import org.springframework.boot.SpringApplication
77
import org.springframework.boot.autoconfigure.SpringBootApplication
8+
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
89

9-
@SpringBootApplication
1010
@CompileStatic
11+
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration)
1112
class Application implements CommandLineRunner {
1213

1314
static void main(String[] args) throws Exception {

examples/spring-boot-hibernate5/src/main/groovy/example/BookController.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package example
22

3+
import grails.gorm.transactions.ReadOnly
34
import groovy.transform.CompileStatic
45
import org.springframework.beans.factory.annotation.Autowired
56
import org.springframework.web.bind.annotation.PathVariable
67
import org.springframework.web.bind.annotation.RequestMapping
78
import org.springframework.web.bind.annotation.RestController
89

9-
@RestController
1010
@CompileStatic
11+
@RestController
1112
class BookController {
1213

1314
@Autowired
1415
BookService bookService
1516

17+
@ReadOnly
1618
@RequestMapping("/books")
1719
List<Book> books() {
1820
Book.list()
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
hibernate:
2-
cache:
3-
queries: false
4-
use_second_level_cache: true
5-
use_query_cache: false
6-
region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
2+
cache:
3+
queries: false
4+
use_second_level_cache: false
5+
use_query_cache: false
76
dataSource:
8-
pooled: true
9-
jmxExport: true
10-
driverClassName: org.h2.Driver
11-
dbCreate: create-drop
12-
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
7+
pooled: true
8+
driverClassName: org.h2.Driver
9+
dbCreate: create-drop
10+
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ picocliVersion=4.7.6
1919
snakeYamlVersion=2.3
2020
slf4jVersion=2.0.16
2121
spockVersion=2.3-groovy-4.0
22+
springBootGradlePluginVersion=3.3.5
2223
testingSupportVersion=4.0.0-SNAPSHOT
2324
tomcatLog4jVersion=8.5.2
2425
tomcatVersion=10.1.31

0 commit comments

Comments
 (0)