From 17c51e8efc571e93d439b576c49088ae19ee736b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 13:04:23 +0000 Subject: [PATCH] Migrate to Spring Boot 3.3.5 / Java 21 - Bump spring-boot-starter-parent and spring-boot-gradle-plugin to 3.3.5 - Update java.version / sourceCompatibility / targetCompatibility to 21 - Maven: change packaging from pom to jar, drop spring-boot-properties-migrator - Gradle: replace deprecated compile/testCompile with implementation/testImplementation, use bootJar archiveBaseName/archiveVersion, add spring-boot-starter-jdbc and h2 - Bump Maven wrapper to 3.9.9 and Gradle wrapper to 8.10 - Application.java: fix H2 2.x DROP TABLE IF EXISTS syntax, switch jdbcTemplate.query to varargs parameter style, remove dead gturnquist-quoters.cfapps.io REST calls - Convert Greeting model to a Java 21 record - Remove unused Quote and Value model classes - Refresh README for Java 21 / Spring Boot 3.3.x Co-Authored-By: Lukas Burger --- .mvn/wrapper/maven-wrapper.properties | 2 +- README.md | 31 ++++++++++++++------- build.gradle | 17 ++++++------ gradle/wrapper/gradle-wrapper.properties | 3 +-- gradlew | 0 mvnw | 0 pom.xml | 11 +++----- src/main/java/hello/Application.java | 25 +++++------------ src/main/java/hello/model/Greeting.java | 19 +------------ src/main/java/hello/model/Quote.java | 34 ------------------------ src/main/java/hello/model/Value.java | 33 ----------------------- 11 files changed, 42 insertions(+), 133 deletions(-) mode change 100644 => 100755 gradlew mode change 100644 => 100755 mvnw delete mode 100644 src/main/java/hello/model/Quote.java delete mode 100644 src/main/java/hello/model/Value.java diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index c954cec..11213b0 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/README.md b/README.md index 2b09400..dab31d3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # springboot-java8 -The project is made on spring boot. The project summarize the new features present in Java 8. +The project is made on Spring Boot 3.3.x and runs on Java 21. It originally summarized Java 8 features +and has since been migrated to a modern stack while preserving those examples. It contain list of harcoded topics list. You can call the apis's with POSTMAN to add,delete,update Topic list In addition, it uses -1) Java 8 NIO methods +1) Java NIO methods 2) String operations 3) Stream operations 4) IntStream functions @@ -11,7 +12,7 @@ In addition, it uses 7) Optional datatype 8) Foreach loops 9) Default and Static methods in interface -10) Java 8 LocalDateTime API +10) `java.time` LocalDateTime API 11) Pattern @@ -76,20 +77,28 @@ GET /datetime ### Prerequisites -1) Java sdk +1) Java 21 (JDK 21) 2) POSTMAN -### Installing +### Installing / Running +Build and run with the Maven wrapper: +``` +./mvnw clean package +java -jar target/gs-spring-boot-0.1.0.jar +``` + +Or with the Gradle wrapper: ``` -1) Download or clone -2) Import the project -3) Run on location machine -4) Open Postman, to call API's ( localhost:8080 ) +./gradlew bootRun ``` +Then open Postman or curl the endpoints at `http://localhost:8080`. + +> Note: the previous random-quote integration backed by `gturnquist-quoters.cfapps.io` +> has been removed because that endpoint is no longer reachable. ## Helpful Links Spring: @@ -125,7 +134,9 @@ https://dzone.com/articles/java-8-friday-goodies-new-new ## Built With -* [Maven](https://maven.apache.org/) - Dependency Management +* [Spring Boot 3.3.x](https://spring.io/projects/spring-boot) +* [Java 21](https://openjdk.org/projects/jdk/21/) +* [Maven](https://maven.apache.org/) or [Gradle](https://gradle.org/) for builds ## Authors diff --git a/build.gradle b/build.gradle index 09f1083..efb3de1 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE") + classpath("org.springframework.boot:spring-boot-gradle-plugin:3.3.5") } } @@ -14,19 +14,20 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' bootJar { - baseName = 'gs-spring-boot' - version = '0.1.0' + archiveBaseName = 'gs-spring-boot' + archiveVersion = '0.1.0' } repositories { mavenCentral() } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 21 +targetCompatibility = 21 dependencies { - compile("org.springframework.boot:spring-boot-starter-web") - testCompile("junit:junit") + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-jdbc") + implementation("com.h2database:h2") + testImplementation("org.springframework.boot:spring-boot-starter-test") } - diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a2ff3cc..c619e22 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Mar 01 09:01:15 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/mvnw b/mvnw old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml index 63f5cbd..cb90ba8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,21 +5,16 @@ org.springframework gs-spring-boot - pom + jar 0.1.0 org.springframework.boot spring-boot-starter-parent - 2.0.2.RELEASE + 3.3.5 - - org.springframework.boot - spring-boot-properties-migrator - runtime - org.springframework.boot spring-boot-starter-web @@ -35,7 +30,7 @@ - 1.8 + 21 diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java index 7cf8faf..4772bf2 100644 --- a/src/main/java/hello/Application.java +++ b/src/main/java/hello/Application.java @@ -5,7 +5,6 @@ import java.util.stream.Collectors; import hello.model.Customer; -import hello.model.Quote; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -26,18 +25,14 @@ public class Application implements CommandLineRunner { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); - + System.out.println("Let's inspect the beans provided by Spring Boot:"); - + String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } - - RestTemplate restTemplate = new RestTemplate(); - Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class); - log.info(quote.toString()); } @@ -46,15 +41,6 @@ public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } - @Bean - public CommandLineRunner run(RestTemplate restTemplate) throws Exception { - return args -> { - Quote quote = restTemplate.getForObject( - "http://gturnquist-quoters.cfapps.io/api/random", Quote.class); - log.info(quote.toString()); - }; - } - @Autowired JdbcTemplate jdbcTemplate; @@ -63,7 +49,7 @@ public CommandLineRunner run(RestTemplate restTemplate) throws Exception { public void run(String... args) throws Exception { log.info("Creating tables"); - jdbcTemplate.execute("DROP TABLE customers IF EXISTS"); + jdbcTemplate.execute("DROP TABLE IF EXISTS customers"); jdbcTemplate.execute("CREATE TABLE customers(id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))"); // Split up the array of whole names into an array of first/last names @@ -80,8 +66,9 @@ public void run(String... args) throws Exception { log.info("Querying for customer records where first_name = 'Josh':"); jdbcTemplate.query( - "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[]{"Josh"}, - (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")) + "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", + (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")), + "Josh" ).forEach(customer -> log.info(customer.toString())); } diff --git a/src/main/java/hello/model/Greeting.java b/src/main/java/hello/model/Greeting.java index f2e7772..135b2fb 100644 --- a/src/main/java/hello/model/Greeting.java +++ b/src/main/java/hello/model/Greeting.java @@ -1,21 +1,4 @@ package hello.model; -public class Greeting { - private final long id; - private final String content; - - public Greeting(long id, String content) { - this.id = id; - this.content = content; - } - - - public long getId() { - - return id; - } - - public String getContent() { - return content; - } +public record Greeting(long id, String content) { } diff --git a/src/main/java/hello/model/Quote.java b/src/main/java/hello/model/Quote.java deleted file mode 100644 index 2178a6d..0000000 --- a/src/main/java/hello/model/Quote.java +++ /dev/null @@ -1,34 +0,0 @@ -package hello.model; - -public class Quote { - private String type; - private Value value; - - @Override - public String toString() { - return "Quote{" + - "type='" + type + '\'' + - ", value=" + value + - '}'; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Value getValue() { - return value; - } - - public void setValue(Value value) { - this.value = value; - } - - public Quote() { - - } -} diff --git a/src/main/java/hello/model/Value.java b/src/main/java/hello/model/Value.java deleted file mode 100644 index 272be70..0000000 --- a/src/main/java/hello/model/Value.java +++ /dev/null @@ -1,33 +0,0 @@ -package hello.model; - -public class Value { - private Long id; - private String quote; - - public Value() { - } - - @Override - public String toString() { - return "Value{" + - "id=" + id + - ", quote='" + quote + '\'' + - '}'; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getQuote() { - return quote; - } - - public void setQuote(String quote) { - this.quote = quote; - } -}