Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand All @@ -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")
}

3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Empty file modified gradlew
100644 → 100755
Empty file.
Empty file modified mvnw
100644 → 100755
Empty file.
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@

<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<packaging>pom</packaging>
<packaging>jar</packaging>
<version>0.1.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<version>3.3.5</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -35,7 +30,7 @@
</dependencies>

<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
</properties>


Expand Down
25 changes: 6 additions & 19 deletions src/main/java/hello/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}


Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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()));

}
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/hello/model/Greeting.java
Original file line number Diff line number Diff line change
@@ -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) {
}
34 changes: 0 additions & 34 deletions src/main/java/hello/model/Quote.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/main/java/hello/model/Value.java

This file was deleted.