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..e10df3f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # springboot-java8 -The project is made on spring boot. The project summarize the new features present 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 +A Spring Boot project demonstrating Java features including streams, lambdas, NIO, and more. +It contains a list of hardcoded topics. You can call the APIs with POSTMAN to add, delete, update the Topic list. +In addition, it uses: +1) Java NIO methods 2) String operations 3) Stream operations 4) IntStream functions @@ -11,14 +11,32 @@ In addition, it uses 7) Optional datatype 8) Foreach loops 9) Default and Static methods in interface -10) Java 8 LocalDateTime API +10) Java LocalDateTime API 11) Pattern +## Requirements + +- **Java 21** +- **Spring Boot 3.4.5** +- **Maven 3.9.9** (via Maven Wrapper) or **Gradle 8.12** (via Gradle Wrapper) + ## Getting Started -1) Download or clone the project with link -(https://github.com/RehmanMuradAli/springboot-java8/) + +### Build & Run with Maven +```bash +./mvnw clean package +java -jar target/gs-spring-boot-0.1.0.jar +``` + +### Build & Run with Gradle +```bash +./gradlew build +java -jar build/libs/gs-spring-boot-0.1.0.jar +``` + +The application starts on `http://localhost:8080`. ## Available API's @@ -67,41 +85,22 @@ File Operations on Topic List ``` GET /topic/file/operation ``` -Java 8 Date Time example +Java Date Time example ``` GET /datetime ``` -### Prerequisites - -1) Java sdk -2) POSTMAN - -### Installing - - - -``` -1) Download or clone -2) Import the project -3) Run on location machine -4) Open Postman, to call API's ( localhost:8080 ) -``` - - ## Helpful Links Spring: https://spring.io/guides -Java 8: +Java: http://www.baeldung.com/java-8-functional-interfaces -http://winterbe.com/posts/2015/05/22/java8-concurrency-tutorial-atomic-concurrent-map-examples/ - https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/ @@ -126,9 +125,8 @@ https://dzone.com/articles/java-8-friday-goodies-new-new ## Built With * [Maven](https://maven.apache.org/) - Dependency Management +* [Spring Boot](https://spring.io/projects/spring-boot) - Application Framework ## Authors -* **Rehman Murad Ali** - - +* **Rehman Murad Ali** diff --git a/build.gradle b/build.gradle index 09f1083..18b69c4 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.4.5") } } @@ -22,11 +22,13 @@ 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") + runtimeOnly("com.h2database:h2") + testImplementation("junit:junit") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a2ff3cc..6e53bb5 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.12-bin.zip diff --git a/pom.xml b/pom.xml index 63f5cbd..2aa2606 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.4.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..2a52f13 100644 --- a/src/main/java/hello/Application.java +++ b/src/main/java/hello/Application.java @@ -5,18 +5,14 @@ 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; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.web.client.RestTemplate; @SpringBootApplication public class Application implements CommandLineRunner { @@ -34,25 +30,6 @@ public static void main(String[] args) { 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()); - } - - - @Bean - 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()); - }; } @@ -63,7 +40,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