diff --git a/.gitignore b/.gitignore
index 57f1cb2..7dd9c69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
-/.idea/
\ No newline at end of file
+/.idea/
+target/
+build/
+.gradle/
diff --git a/.gitignore.txt b/.gitignore.txt
deleted file mode 100644
index 57f1cb2..0000000
--- a/.gitignore.txt
+++ /dev/null
@@ -1 +0,0 @@
-/.idea/
\ No newline at end of file
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index c954cec..4465bd9 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.6/apache-maven-3.9.6-bin.zip
diff --git a/README.md b/README.md
index 2b09400..0525d34 100644
--- a/README.md
+++ b/README.md
@@ -17,9 +17,24 @@ In addition, it uses
## Getting Started
+
+Requires a locally installed JDK 17 (the Gradle build pins a Java 17 toolchain and no toolchain resolver is configured, so it will not download one).
+
1) Download or clone the project with link
(https://github.com/RehmanMuradAli/springboot-java8/)
+2) Build and run with Maven
+```
+./mvnw clean package
+java -jar target/gs-spring-boot-0.1.0.jar
+```
+
+or with Gradle
+```
+./gradlew clean bootJar
+java -jar build/libs/gs-spring-boot-0.1.0.jar
+```
+
## Available API's
Greetings
@@ -76,7 +91,7 @@ GET /datetime
### Prerequisites
-1) Java sdk
+1) JDK 17
2) POSTMAN
### Installing
@@ -126,6 +141,7 @@ https://dzone.com/articles/java-8-friday-goodies-new-new
## Built With
* [Maven](https://maven.apache.org/) - Dependency Management
+* [Gradle](https://gradle.org/) - Alternative build, kept in sync with the Maven build
## Authors
diff --git a/application.properties b/application.properties
deleted file mode 100644
index d3baf26..0000000
--- a/application.properties
+++ /dev/null
@@ -1 +0,0 @@
-#server.port = 8081
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 09f1083..a007185 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,8 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
+ classpath("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
+ classpath("io.spring.gradle:dependency-management-plugin:1.0.15.RELEASE")
}
}
@@ -14,19 +15,29 @@ 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
+java {
+ toolchain {
+ languageVersion = JavaLanguageVersion.of(17)
+ }
+}
+
+tasks.withType(JavaCompile) {
+ options.release = 17
+}
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")
+ runtimeOnly("org.springframework.boot:spring-boot-properties-migrator")
+ testImplementation("junit:junit")
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index a2ff3cc..03a8d13 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-7.6.4-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..7179f46 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,13 +5,13 @@
org.springframework
gs-spring-boot
- pom
+ jar
0.1.0
org.springframework.boot
spring-boot-starter-parent
- 2.0.2.RELEASE
+ 2.7.18
@@ -31,11 +31,15 @@
com.h2database
h2
+ runtime
- 1.8
+ 17
+ 17
+ 3.13.0
+ 3.5.6
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..5e94bef
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'gs-spring-boot'
diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java
index 7cf8faf..54348e7 100644
--- a/src/main/java/hello/Application.java
+++ b/src/main/java/hello/Application.java
@@ -16,6 +16,7 @@
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
@@ -23,6 +24,8 @@ 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);
@@ -35,9 +38,16 @@ public static void main(String[] args) {
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());
+ logRandomQuote(new RestTemplate());
+ }
+
+ private static void logRandomQuote(RestTemplate restTemplate) {
+ try {
+ Quote quote = restTemplate.getForObject(QUOTE_URL, Quote.class);
+ log.info(String.valueOf(quote));
+ } catch (RestClientException e) {
+ log.warn("Could not fetch a quote from {}: {}", QUOTE_URL, e.getMessage());
+ }
}
@@ -48,11 +58,7 @@ 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());
- };
+ return args -> logRandomQuote(restTemplate);
}
@@ -80,8 +86,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/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 0000000..9e0676c
--- /dev/null
+++ b/src/main/resources/application.properties
@@ -0,0 +1 @@
+#server.port=8081
diff --git a/target/classes/hello/Application.class b/target/classes/hello/Application.class
deleted file mode 100644
index 245a020..0000000
Binary files a/target/classes/hello/Application.class and /dev/null differ
diff --git a/target/classes/hello/controller/GreetingController.class b/target/classes/hello/controller/GreetingController.class
deleted file mode 100644
index 1149660..0000000
Binary files a/target/classes/hello/controller/GreetingController.class and /dev/null differ
diff --git a/target/classes/hello/controller/HelloController.class b/target/classes/hello/controller/HelloController.class
deleted file mode 100644
index 79b82ce..0000000
Binary files a/target/classes/hello/controller/HelloController.class and /dev/null differ
diff --git a/target/classes/hello/controller/TopicController.class b/target/classes/hello/controller/TopicController.class
deleted file mode 100644
index c32cad5..0000000
Binary files a/target/classes/hello/controller/TopicController.class and /dev/null differ
diff --git a/target/classes/hello/declaration/CustomPredicate.class b/target/classes/hello/declaration/CustomPredicate.class
deleted file mode 100644
index e35803f..0000000
Binary files a/target/classes/hello/declaration/CustomPredicate.class and /dev/null differ
diff --git a/target/classes/hello/declaration/TimeClient.class b/target/classes/hello/declaration/TimeClient.class
deleted file mode 100644
index a077c3b..0000000
Binary files a/target/classes/hello/declaration/TimeClient.class and /dev/null differ
diff --git a/target/classes/hello/model/Customer.class b/target/classes/hello/model/Customer.class
deleted file mode 100644
index 06e7307..0000000
Binary files a/target/classes/hello/model/Customer.class and /dev/null differ
diff --git a/target/classes/hello/model/Greeting.class b/target/classes/hello/model/Greeting.class
deleted file mode 100644
index f875277..0000000
Binary files a/target/classes/hello/model/Greeting.class and /dev/null differ
diff --git a/target/classes/hello/model/Quote.class b/target/classes/hello/model/Quote.class
deleted file mode 100644
index 3ec6c6c..0000000
Binary files a/target/classes/hello/model/Quote.class and /dev/null differ
diff --git a/target/classes/hello/model/SimpleTimeClient.class b/target/classes/hello/model/SimpleTimeClient.class
deleted file mode 100644
index f9bdddd..0000000
Binary files a/target/classes/hello/model/SimpleTimeClient.class and /dev/null differ
diff --git a/target/classes/hello/model/Topic.class b/target/classes/hello/model/Topic.class
deleted file mode 100644
index 3a53aa5..0000000
Binary files a/target/classes/hello/model/Topic.class and /dev/null differ
diff --git a/target/classes/hello/model/Value.class b/target/classes/hello/model/Value.class
deleted file mode 100644
index 862a68f..0000000
Binary files a/target/classes/hello/model/Value.class and /dev/null differ
diff --git a/target/classes/hello/service/TopicService.class b/target/classes/hello/service/TopicService.class
deleted file mode 100644
index b9f4992..0000000
Binary files a/target/classes/hello/service/TopicService.class and /dev/null differ
diff --git a/target/classes/public/index.html b/target/classes/public/index.html
deleted file mode 100644
index 566549b..0000000
--- a/target/classes/public/index.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
- Title
-
-
-
-
-
\ No newline at end of file