diff --git a/.gitignore b/.gitignore
index 57f1cb2..171f386 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
-/.idea/
\ No newline at end of file
+/.idea/
+/target/
+/build/
+/.gradle/
diff --git a/README.md b/README.md
index 2b09400..a78ec74 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# 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 and Java 21. It summarizes the functional-programming features introduced in Java 8.
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
diff --git a/build.gradle b/build.gradle
index 09f1083..68d6697 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,32 +1,35 @@
-buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
- }
+plugins {
+ id 'java'
+ id 'eclipse'
+ id 'idea'
+ id 'org.springframework.boot' version '3.3.4'
+ id 'io.spring.dependency-management' version '1.1.6'
}
-apply plugin: 'java'
-apply plugin: 'eclipse'
-apply plugin: 'idea'
-apply plugin: 'org.springframework.boot'
-apply plugin: 'io.spring.dependency-management'
+group = 'org.springframework'
+version = '0.1.0'
+
+java {
+ toolchain {
+ languageVersion = JavaLanguageVersion.of(21)
+ }
+}
bootJar {
- baseName = 'gs-spring-boot'
- version = '0.1.0'
+ archiveBaseName = 'gs-spring-boot'
}
repositories {
mavenCentral()
}
-sourceCompatibility = 1.8
-targetCompatibility = 1.8
-
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'
+ runtimeOnly 'com.h2database:h2'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
+tasks.named('test') {
+ useJUnitPlatform()
+}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index a2ff3cc..0a55694 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ 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.2-bin.zip
diff --git a/pom.xml b/pom.xml
index 63f5cbd..77504fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,21 +5,17 @@
org.springframework
gs-spring-boot
- pom
+ jar
0.1.0
org.springframework.boot
spring-boot-starter-parent
- 2.0.2.RELEASE
+ 3.3.4
+
-
- org.springframework.boot
- spring-boot-properties-migrator
- runtime
-
org.springframework.boot
spring-boot-starter-web
@@ -32,10 +28,15 @@
com.h2database
h2
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
- 1.8
+ 21
diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java
index 7cf8faf..f9ca78d 100644
--- a/src/main/java/hello/Application.java
+++ b/src/main/java/hello/Application.java
@@ -16,28 +16,26 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class Application implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(Application.class);
+ private static final String QUOTE_URL = "http://gturnquist-quoters.cfapps.io/api/random";
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());
}
@@ -49,9 +47,12 @@ public RestTemplate restTemplate(RestTemplateBuilder builder) {
@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());
+ try {
+ Quote quote = restTemplate.getForObject(QUOTE_URL, Quote.class);
+ log.info(String.valueOf(quote));
+ } catch (RestClientException e) {
+ log.warn("Could not fetch quote from {}: {}", QUOTE_URL, e.getMessage());
+ }
};
}
@@ -63,8 +64,8 @@ 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("CREATE TABLE customers(id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))");
+ jdbcTemplate.execute("DROP TABLE IF EXISTS customers");
+ jdbcTemplate.execute("CREATE TABLE customers(id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255))");
// Split up the array of whole names into an array of first/last names
List