Merge branch 'eugenp:master' into master

This commit is contained in:
Kingsley✨ 2023-04-22 08:36:53 +00:00 committed by GitHub
commit c34aacc618
74 changed files with 684 additions and 283 deletions

View File

@ -5,3 +5,5 @@ This module contains articles about core Java input/output(IO) APIs.
### Relevant Articles:
- [Constructing a Relative Path From Two Absolute Paths in Java](https://www.baeldung.com/java-relative-path-absolute)
- [Java Scanner Taking a Character Input](https://www.baeldung.com/java-scanner-character-input)
- [Get the Desktop Path in Java](https://www.baeldung.com/java-desktop-path)

View File

@ -0,0 +1,85 @@
package com.baeldung.scanner;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.InputMismatchException;
import java.util.Scanner;
import org.junit.jupiter.api.Test;
public class NextLineVsNextIntUnitTest {
@Test
void whenInputLineIsNumber_thenNextLineAndNextIntBothWork() {
String input = "42\n";
//nextLine()
Scanner sc1 = new Scanner(input);
int num1 = Integer.parseInt(sc1.nextLine());
assertEquals(42, num1);
//nextInt()
Scanner sc2 = new Scanner(input);
int num2 = sc2.nextInt();
assertEquals(42, num2);
}
@Test
void whenInputIsNotValidNumber_thenNextLineAndNextIntThrowDifferentException() {
String input = "Nan\n";
//nextLine() -> NumberFormatException
Scanner sc1 = new Scanner(input);
assertThrows(NumberFormatException.class, () -> Integer.parseInt(sc1.nextLine()));
//nextInt() -> InputMismatchException
Scanner sc2 = new Scanner(input);
assertThrows(InputMismatchException.class, sc2::nextInt);
}
@Test
void whenUsingNextInt_thenTheNextTokenAfterItFailsToParseIsNotConsumed() {
String input = "42 is a magic number\n";
//nextInt() to read '42'
Scanner sc2 = new Scanner(input);
int num2 = sc2.nextInt();
assertEquals(42, num2);
// call nextInt() again on "is"
assertThrows(InputMismatchException.class, sc2::nextInt);
String theNextToken = sc2.next();
assertEquals("is", theNextToken);
theNextToken = sc2.next();
assertEquals("a", theNextToken);
}
@Test
void whenReadingTwoInputLines_thenNextLineAndNextIntBehaveDifferently() {
String input = new StringBuilder().append("42\n")
.append("It is a magic number.\n")
.toString();
//nextLine()
Scanner sc1 = new Scanner(input);
int num1 = Integer.parseInt(sc1.nextLine());
String nextLineText1 = sc1.nextLine();
assertEquals(42, num1);
assertEquals("It is a magic number.", nextLineText1);
//nextInt()
Scanner sc2 = new Scanner(input);
int num2 = sc2.nextInt();
assertEquals(42, num2);
// nextInt() leaves the newline character (\n) behind
String nextLineText2 = sc2.nextLine();
assertEquals("", nextLineText2);
}
}

View File

@ -14,5 +14,4 @@ This module contains articles about core Java non-blocking input and output (IO)
- [What Is the Difference Between NIO and NIO.2?](https://www.baeldung.com/java-nio-vs-nio-2)
- [Guide to ByteBuffer](https://www.baeldung.com/java-bytebuffer)
- [Find Files that Match Wildcard Strings in Java](https://www.baeldung.com/java-files-match-wildcard-strings)
- [Get the Desktop Path in Java](https://www.baeldung.com/java-desktop-path)
- [[<-- Prev]](/core-java-modules/core-java-nio)

View File

@ -10,4 +10,3 @@
- [Understanding the Difference Between Stream.of() and IntStream.range()](https://www.baeldung.com/java-stream-of-and-intstream-range)
- [Check if Object Is an Array in Java](https://www.baeldung.com/java-check-if-object-is-an-array)
- [Mapping an Array of Integers to Strings Using Java Streams](https://www.baeldung.com/java-stream-integer-array-to-strings)
- [Difference Between parallelStream() and stream().parallel() in Java](https://www.baeldung.com/java-parallelstream-vs-stream-parallel)

View File

@ -0,0 +1 @@
- [Difference Between parallelStream() and stream().parallel() in Java](https://www.baeldung.com/java-parallelstream-vs-stream-parallel)

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-streams-5</artifactId>
<name>core-java-streams-5</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit-jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>core-java-streams-4</finalName>
<resources>
<resource>
<directory>../core-java-streams-4/src/main</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- testing -->
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
</project>

View File

@ -34,4 +34,4 @@ public class Book {
public void setYearPublished(int yearPublished) {
this.yearPublished = yearPublished;
}
}
}

View File

@ -37,4 +37,4 @@ public class BookSpliterator<T> implements Spliterator<T> {
public int characteristics() {
return CONCURRENT;
}
}
}

View File

@ -1,6 +1,5 @@
package parallelstream;
package com.baeldung.parallelstream;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;

View File

@ -15,13 +15,7 @@
</parent>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${tools.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<build>
@ -32,10 +26,25 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source.version}</source>
<target>${maven.compiler.target.version}</target>
<compilerArgs>
<arg>--add-exports=jdk.jdi/com.sun.jdi=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<tools.version>1.8</tools.version>
<maven.compiler.source.version>17</maven.compiler.source.version>
<maven.compiler.target.version>17</maven.compiler.target.version>
</properties>
</project>

1
libraries-ai/README.md Normal file
View File

@ -0,0 +1 @@

33
libraries-ai/pom.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>libraries-ai</artifactId>
<name>libraries-ai</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>${stanford-corenlp.version}</version>
</dependency>
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>${opennlp-tools.version}</version>
</dependency>
</dependencies>
<properties>
<stanford-corenlp.version>4.5.3</stanford-corenlp.version>
<opennlp-tools.version>2.1.1</opennlp-tools.version>
</properties>
</project>

View File

@ -0,0 +1,41 @@
package com.baeldung.nlp;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;
import org.junit.Test;
import java.util.List;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
public class CoreNLPTokenizerUnitTest {
@Test
public void givenSampleText_whenTokenize_thenExpectedTokensReturned() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String text = "The german shepard display an act of kindness";
Annotation document = new Annotation(text);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
StringBuilder tokens = new StringBuilder();
for (CoreMap sentence : sentences) {
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
String word = token.get(CoreAnnotations.TextAnnotation.class);
tokens.append(word)
.append(" ");
}
}
assertEquals("The german shepard display an act of kindness", tokens.toString()
.trim());
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.nlp;
import opennlp.tools.langdetect.Language;
import opennlp.tools.langdetect.LanguageDetectorME;
import opennlp.tools.langdetect.LanguageDetectorModel;
import org.junit.jupiter.api.Test;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
class OpenNLPLanguageDetector {
@Test
public void givenTextInEnglish_whenDetectLanguage_thenReturnsEnglishLanguageCode() {
String text = "the dream my father told me";
LanguageDetectorModel model;
try (InputStream modelIn = new FileInputStream("langdetect-183.bin")) {
model = new LanguageDetectorModel(modelIn);
} catch (IOException e) {
return;
}
LanguageDetectorME detector = new LanguageDetectorME(model);
Language language = detector.predictLanguage(text);
assertEquals("eng", language.getLang());
}
}

View File

@ -134,6 +134,11 @@
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>${swagger-parser.version}</version>
</dependency>
</dependencies>
<build>
@ -171,6 +176,7 @@
<derive4j.version>1.1.0</derive4j.version>
<awaitility.version>3.0.0</awaitility.version>
<univocity.version>2.8.4</univocity.version>
<swagger-parser.version>2.1.13</swagger-parser.version>
</properties>
</project>

View File

@ -0,0 +1,92 @@
package com.baeldung.swaggerparser;
import java.util.List;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.responses.ApiResponses;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
public class SwaggerParser {
private static String OPENAPI_SPECIFICATION_STRING = "{\"openapi\":\"3.0.0\",\"info\":{\"title\":\"User APIs\",\"version\":\"1.0\"},\"servers\":[{\"url\":\"https://jsonplaceholder.typicode.com\",\"description\":\"Json Place Holder Service\"}],\"paths\":{\"/users/{id}\":{\"parameters\":[{\"schema\":{\"type\":\"integer\"},\"name\":\"id\",\"in\":\"path\",\"required\":true}],\"get\":{\"summary\":\"Fetch user by ID\",\"tags\":[\"User\"],\"responses\":{\"200\":{\"description\":\"OK\",\"content\":{\"application/json\":{\"schema\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}}}}}}},\"operationId\":\"get-users-user_id\",\"description\":\"Retrieve a specific user by ID\"}}}}";
public static void main(String[] args) {
parseYAMLFile();
parseJSONFile();
parseString();
}
private static void parseString() {
SwaggerParseResult result = new OpenAPIParser().readContents(OPENAPI_SPECIFICATION_STRING, null, null);
OpenAPI openAPI = result.getOpenAPI();
if (openAPI != null) {
printData(openAPI);
}
}
private static void parseJSONFile() {
SwaggerParseResult result = new OpenAPIParser().readLocation("sample.yml", null, null);
OpenAPI openAPI = result.getOpenAPI();
if (openAPI != null) {
printData(openAPI);
}
}
private static void parseYAMLFile() {
SwaggerParseResult result = new OpenAPIParser().readLocation("sample.json", null, null);
OpenAPI openAPI = result.getOpenAPI();
if (openAPI != null) {
printData(openAPI);
}
}
private static void printData(OpenAPI openAPI) {
System.out.println(openAPI.getSpecVersion());
Info info = openAPI.getInfo();
System.out.println(info.getTitle());
System.out.println(info.getVersion());
List<Server> servers = openAPI.getServers();
for (Server server : servers) {
System.out.println(server.getUrl());
System.out.println(server.getDescription());
}
Paths paths = openAPI.getPaths();
paths.entrySet()
.forEach(pathEntry -> {
System.out.println(pathEntry.getKey());
PathItem path = pathEntry.getValue();
System.out.println(path.getGet()
.getSummary());
System.out.println(path.getGet()
.getDescription());
System.out.println(path.getGet()
.getOperationId());
ApiResponses responses = path.getGet()
.getResponses();
responses.entrySet()
.forEach(responseEntry -> {
System.out.println(responseEntry.getKey());
ApiResponse response = responseEntry.getValue();
System.out.println(response.getDescription());
});
});
}
}

View File

@ -0,0 +1,55 @@
{
"openapi": "3.0.0",
"info": {
"title": "User APIs",
"version": "1.0"
},
"servers": [
{
"url": "https://jsonplaceholder.typicode.com",
"description": "Json Place Holder Service"
}
],
"paths": {
"/users/{id}": {
"parameters": [
{
"schema": {
"type": "integer"
},
"name": "id",
"in": "path",
"required": true
}
],
"get": {
"summary": "Fetch user by ID",
"tags": [
"User"
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
}
}
}
},
"operationId": "get-users-user_id",
"description": "Retrieve a specific user by ID"
}
}
}
}

View File

@ -0,0 +1,33 @@
openapi: 3.0.0
info:
title: User APIs
version: '1.0'
servers:
- url: https://jsonplaceholder.typicode.com
description: Json Place Holder Service
paths:
/users/{id}:
parameters:
- schema:
type: integer
name: id
in: path
required: true
get:
summary: Fetch user by ID
tags:
- User
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
operationId: get-users-user_id
description: Retrieve a specific user by ID

View File

@ -0,0 +1,65 @@
package com.baeldung.swaggerparser;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.junit.jupiter.api.Test;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
public class SwaggerParserUnitTest {
private static String OPENAPI_SPECIFICATION_STRING = "{\"openapi\":\"3.0.0\",\"info\":{\"title\":\"User APIs\",\"version\":\"1.0\"},\"servers\":[{\"url\":\"https://jsonplaceholder.typicode.com\",\"description\":\"Json Place Holder Service\"}],\"paths\":{\"/users/{id}\":{\"parameters\":[{\"schema\":{\"type\":\"integer\"},\"name\":\"id\",\"in\":\"path\",\"required\":true}],\"get\":{\"summary\":\"Fetch user by ID\",\"tags\":[\"User\"],\"responses\":{\"200\":{\"description\":\"OK\",\"content\":{\"application/json\":{\"schema\":{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"}}}}}}},\"operationId\":\"get-users-user_id\",\"description\":\"Retrieve a specific user by ID\"}}}}";
@Test
public void givenAValidOpenAPIYAMLFile_whenParsing_thenCheckIfParsed() {
SwaggerParseResult result = new OpenAPIParser().readLocation("valid-openapi-sample.yml", null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
}
@Test
public void givenAValidOpenAPIYAMLFile_whenParsing_thenCheckIfNotErrors() {
SwaggerParseResult result = new OpenAPIParser().readLocation("valid-openapi-sample.yml", null, null);
List<String> messages = result.getMessages();
assertTrue(messages.isEmpty());
}
@Test
public void givenAnInvalidOpenAPIYAMLFile_whenParsing_thenCheckIfErrors() {
SwaggerParseResult result = new OpenAPIParser().readLocation("invalid-openapi-sample.yml", null, null);
List<String> messages = result.getMessages();
assertFalse(messages.isEmpty());
}
@Test
public void givenAValidOpenAPISpecificationString_whenParsing_thenCheckIfParsed() {
SwaggerParseResult result = new OpenAPIParser().readContents(OPENAPI_SPECIFICATION_STRING, null, null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
}
@Test
public void givenAValidOpenAPISpecificationString_whenParsing_thenCheckIfNotErrors() {
SwaggerParseResult result = new OpenAPIParser().readLocation(OPENAPI_SPECIFICATION_STRING, null, null);
List<String> messages = result.getMessages();
assertNull(messages);
}
}

View File

@ -0,0 +1,32 @@
openapi: 3.0.0
info:
title: User APIs
version: '1.0'
servers:
- description: Json Place Holder Service
paths:
/users/{id}:
parameters:
- schema:
type: integer
name: id
in: path
required: true
get:
summary: Fetch user by ID
tags:
- User
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
operationId: get-users-user_id
description: Retrieve a specific user by ID

View File

@ -0,0 +1,33 @@
openapi: 3.0.0
info:
title: User APIs
version: '1.0'
servers:
- url: https://jsonplaceholder.typicode.com
description: Json Place Holder Service
paths:
/users/{id}:
parameters:
- schema:
type: integer
name: id
in: path
required: true
get:
summary: Fetch user by ID
tags:
- User
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
operationId: get-users-user_id
description: Retrieve a specific user by ID

13
pom.xml
View File

@ -354,8 +354,6 @@
<!-- <module>grails</module> --> <!-- Not a maven project -->
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->
<module>java-jdi</module>
<module>jetbrains</module>
<!-- <module>lagom</module> --> <!-- Not a maven project -->
<module>language-interop</module>
@ -547,8 +545,6 @@
<!-- <module>grails</module> --> <!-- Not a maven project -->
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->
<module>java-jdi</module>
<!-- <module>lagom</module> --> <!-- Not a maven project -->
<module>language-interop</module>
@ -800,7 +796,6 @@
<!-- <module>core-java-modules/core-java-17</module> --> <!-- uses preview features, to be decided how to handle -->
<!-- <module>core-java-modules/core-java-19</module> --> <!-- uses preview features, to be decided how to handle -->
<module>custom-pmd</module>
<module>spring-core-6</module>
<module>data-structures</module>
<module>ddd-contexts</module>
<module>jackson-modules</module>
@ -868,7 +863,7 @@
<module>hystrix</module>
<module>jackson-simple</module>
<module>java-blockchain</module>
<module>java-jdi</module>
<module>java-rmi</module>
<module>java-spi</module>
<module>javax-sound</module>
@ -923,7 +918,6 @@
<module>spring-activiti</module>
<module>spring-core-2</module>
<module>spring-core-3</module>
<module>spring-core-5</module>
<module>spring-di-3</module>
<module>spring-cucumber</module>
@ -1053,7 +1047,6 @@
<module>spring-aop</module>
<module>spring-aop-2</module>
<module>custom-pmd</module>
<module>spring-core-6</module>
<module>data-structures</module>
<module>ddd-contexts</module>
<module>jackson-modules</module>
@ -1123,7 +1116,7 @@
<module>hystrix</module>
<module>jackson-simple</module>
<module>java-blockchain</module>
<module>java-jdi</module>
<module>java-rmi</module>
<module>java-spi</module>
<module>javax-sound</module>
@ -1152,6 +1145,7 @@
<module>libraries-http</module>
<module>libraries-http-2</module>
<module>libraries-io</module>
<module>libraries-ai</module>
<module>libraries-primitive</module>
<module>libraries-rpc</module>
<module>libraries-server</module>
@ -1178,7 +1172,6 @@
<module>spring-activiti</module>
<module>spring-core-2</module>
<module>spring-core-3</module>
<module>spring-core-5</module>
<module>spring-di-3</module>
<module>spring-cucumber</module>

View File

@ -1,13 +0,0 @@
*.class
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
# Packaged files #
*.jar
*.war
*.ear

View File

@ -6,4 +6,9 @@ This module contains articles about core Spring functionality
- [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes)
- [Spring Events](https://www.baeldung.com/spring-events)
- [Solving Springs “not eligible for auto-proxying” Warning](https://www.baeldung.com/spring-not-eligible-for-auto-proxying)
- [Finding the Spring Version](https://www.baeldung.com/spring-find-version)
- [How Does the Spring Singleton Bean Serve Concurrent Requests?](https://www.baeldung.com/spring-singleton-concurrent-requests)
- [Reinitialize Singleton Bean in Spring Context](https://www.baeldung.com/spring-reinitialize-singleton-bean)
- [Getting the Current ApplicationContext in Spring](https://www.baeldung.com/spring-get-current-applicationcontext)
- More articles: [[<-- prev]](/spring-core)[[next -->]](/spring-core-3)

View File

@ -15,29 +15,15 @@
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${org.springframework.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@ -129,6 +115,11 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- ShedLock -->
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
@ -140,6 +131,10 @@
<artifactId>shedlock-provider-jdbc-template</artifactId>
<version>${shedlock.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
@ -164,8 +159,6 @@
<properties>
<start-class>com.baeldung.sample.App</start-class>
<!-- Spring -->
<org.springframework.version>5.3.0</org.springframework.version>
<annotation-api.version>1.3.2</annotation-api.version>
<!-- persistence -->
<hibernate.version>5.2.5.Final</hibernate.version>

View File

@ -1,20 +1,20 @@
package com.baeldung.version;
import org.springframework.boot.system.JavaVersion;
import org.springframework.boot.system.SystemProperties;
import org.springframework.core.SpringVersion;
public class VersionObtainer {
public String getSpringVersion() {
return SpringVersion.getVersion();
}
public String getJavaVersion() {
return JavaVersion.getJavaVersion().toString();
}
public String getJdkVersion() {
return SystemProperties.get("java.version");
}
}
package com.baeldung.version;
import org.springframework.boot.system.JavaVersion;
import org.springframework.boot.system.SystemProperties;
import org.springframework.core.SpringVersion;
public class VersionObtainer {
public String getSpringVersion() {
return SpringVersion.getVersion();
}
public String getJavaVersion() {
return JavaVersion.getJavaVersion().toString();
}
public String getJdkVersion() {
return SystemProperties.get("java.version");
}
}

View File

@ -0,0 +1 @@
config.file.path=./spring-core-2/src/main/resources/config.properties

View File

@ -1,30 +1,30 @@
package com.baeldung.version;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = VersionObtainer.class)
public class VersionObtainerUnitTest {
public VersionObtainer version = new VersionObtainer();
@Test
public void testGetSpringVersion() {
String res = version.getSpringVersion();
assertThat(res).isNotEmpty();
}
@Test
public void testGetJdkVersion() {
String res = version.getJdkVersion();
assertThat(res).isNotEmpty();
}
@Test
public void testGetJavaVersion() {
String res = version.getJavaVersion();
assertThat(res).isNotEmpty();
}
}
package com.baeldung.version;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = VersionObtainer.class)
public class VersionObtainerUnitTest {
public VersionObtainer version = new VersionObtainer();
@Test
public void testGetSpringVersion() {
String res = version.getSpringVersion();
assertThat(res).isNotEmpty();
}
@Test
public void testGetJdkVersion() {
String res = version.getJdkVersion();
assertThat(res).isNotEmpty();
}
@Test
public void testGetJavaVersion() {
String res = version.getJavaVersion();
assertThat(res).isNotEmpty();
}
}

View File

@ -10,4 +10,5 @@ This module contains articles about core Spring functionality
- [Design Patterns in the Spring Framework](https://www.baeldung.com/spring-framework-design-patterns)
- [Difference Between BeanFactory and ApplicationContext](https://www.baeldung.com/spring-beanfactory-vs-applicationcontext)
- [Custom Scope in Spring](http://www.baeldung.com/spring-custom-scope)
- [The Spring ApplicationContext](https://www.baeldung.com/spring-application-context)
- More articles: [[<-- prev]](/spring-core-2) [[next -->]](/spring-core-4)

View File

@ -6,5 +6,4 @@ This module contains articles about core Spring functionality
- [Creating Spring Beans Through Factory Methods](https://www.baeldung.com/spring-beans-factory-methods)
- [Spring BeanPostProcessor](https://www.baeldung.com/spring-beanpostprocessor)
- [The Spring ApplicationContext](https://www.baeldung.com/spring-application-context)
- More articles: [[<-- prev]](/spring-core-3) [[next -->]](/spring-core-5)
- More articles: [[<-- prev]](/spring-core-3)

View File

@ -1,10 +0,0 @@
## Spring Core
This module contains articles about core Spring functionality.
## Relevant Articles:
- [Solving Springs “not eligible for auto-proxying” Warning](https://www.baeldung.com/spring-not-eligible-for-auto-proxying)
- [Finding the Spring Version](https://www.baeldung.com/spring-find-version)
- [How Does the Spring Singleton Bean Serve Concurrent Requests?](https://www.baeldung.com/spring-singleton-concurrent-requests)
- More articles: [[<-- prev]](../spring-core-4)

View File

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-core-5</artifactId>
<name>spring-core-5</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-spring-5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring-5</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<properties>
<spring.version>5.3.3</spring.version>
<spring-boot-starter.version>2.4.2</spring-boot-starter.version>
</properties>
</project>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="15 seconds" debug="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -1,5 +0,0 @@
### Relevant Articles:
- [Reinitialize Singleton Bean in Spring Context](https://www.baeldung.com/spring-reinitialize-singleton-bean)
- [Getting the Current ApplicationContext in Spring](https://www.baeldung.com/spring-get-current-applicationcontext)
- More articles: [[<-- prev]](../spring-core-5)

View File

@ -1,95 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>spring-core-6</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-core-6</name>
<url>http://www.baeldung.com</url>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-3</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>

View File

@ -1 +0,0 @@
config.file.path=./spring-core-6/src/main/resources/config.properties