Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 27db0d5540 | |||
| edcd08e1b2 | |||
| 038ce5b547 | |||
| b9d1b0257c | |||
| ddbb638242 | |||
| bf2335eda1 | |||
| 1b3b30cae3 | |||
| 4711c3a393 | |||
| 05d80c840d | |||
| 77c51720e9 | |||
| dc99d9404d | |||
| 2b1d680b2c | |||
| 3b344e5c9f | |||
| f2c3c2bf0f | |||
| b90cdd3306 | |||
| c816787e06 | |||
| e8f74069ff | |||
| ae29615530 | |||
| cd46aea7ac |
Generated
+46
@@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="true" />
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="codebank" />
|
||||||
|
<module name="core-java-collections-list" />
|
||||||
|
<module name="spring-data-jpa-repo-2" />
|
||||||
|
<module name="core-java-streams" />
|
||||||
|
<module name="assertion-libraries" />
|
||||||
|
<module name="core-java-io" />
|
||||||
|
<module name="core-java-annotations" />
|
||||||
|
<module name="core-java-8-2" />
|
||||||
|
<module name="core-java-numbers" />
|
||||||
|
<module name="discourse" />
|
||||||
|
<module name="spring-data-redis" />
|
||||||
|
<module name="core-java-strings" />
|
||||||
|
<module name="core-java" />
|
||||||
|
<module name="core-java-11" />
|
||||||
|
<module name="core-java-collections-list-2" />
|
||||||
|
<module name="core-java-collections" />
|
||||||
|
<module name="core-java-datetime-conversion" />
|
||||||
|
<module name="core-java-collections-list-3" />
|
||||||
|
<module name="core-java-8" />
|
||||||
|
<module name="junit-5-basics" />
|
||||||
|
<module name="core-java-collections-3" />
|
||||||
|
<module name="core-java-collections-2" />
|
||||||
|
<module name="activejdbc" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="core-java-11-2" target="11" />
|
||||||
|
<module name="hibernate-annotations" target="1.5" />
|
||||||
|
<module name="hibernate5" target="11" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
<component name="JavacSettings">
|
||||||
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="core-java-streams" options="-parameters" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+64
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11-2/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11-2/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-2/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-2/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-annotations/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-annotations/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-2/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-2/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-3/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-3/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-2/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-2/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-3/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-3/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-datetime-conversion/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-datetime-conversion/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-io/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-io/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-numbers/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-numbers/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-streams/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-streams/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-strings/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-strings/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/core-java/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/core-java-modules/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/hibernate5/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/hibernate5/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-redis/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-redis/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/persistence-modules/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/assertion-libraries/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/assertion-libraries/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/test/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/testing-modules/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/toolkits/codebank/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/toolkits/codebank/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/toolkits/discourse/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/toolkits/discourse/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+40
@@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="ossez-repo-snapshots" />
|
||||||
|
<option name="name" value="OSSEZ Private Snapshots" />
|
||||||
|
<option name="url" value="https://repo.ossez.com/repository/maven-snapshots/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="geodb-repo" />
|
||||||
|
<option name="name" value="GeoDB repository" />
|
||||||
|
<option name="url" value="http://repo.boundlessgeo.com/main/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="ossez-repo-releases" />
|
||||||
|
<option name="name" value="OSSEZ Private Releases" />
|
||||||
|
<option name="url" value="https://repo.ossez.com/repository/maven-releases/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.ossez.com/repository/maven-public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JpaBuddyIdeaProjectConfig">
|
||||||
|
<option name="defaultUnitInitialized" value="true" />
|
||||||
|
<option name="renamerInitialized" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MessDetectorOptionsConfiguration">
|
||||||
|
<option name="transferred" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PHPCSFixerOptionsConfiguration">
|
||||||
|
<option name="transferred" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||||
|
<option name="transferred" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ThriftCompiler">
|
||||||
|
<compilers />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<br>提供 CWIKI.US 项目中使用的代码
|
<br>提供 CWIKI.US 项目中使用的代码
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
所有的 Java 代码使用的是 JDK 11。
|
Java 代码使用的是 JDK 11。
|
||||||
|
|
||||||
你可以通过单击下面连接后访问我们网站,并且访问我们提供的最新有关 Java 的开发资料。
|
你可以通过单击下面连接后访问我们网站,并且访问我们提供的最新有关 Java 的开发资料。
|
||||||
|
|
||||||
@@ -25,7 +25,9 @@
|
|||||||
|
|
||||||
# 公众平台
|
# 公众平台
|
||||||
|
|
||||||
我们建议您通过社区论坛来和我们进行沟通,请关注我们公众平台上的账号
|
我们建议您通过社区论坛来和我们进行沟通,请关注我们公众平台上的账号。
|
||||||
|
|
||||||
|
扫描 QR 关注我们的微信公众号和头条号。
|
||||||
|
|
||||||
## 微信公众号
|
## 微信公众号
|
||||||
|
|
||||||
@@ -33,10 +35,11 @@
|
|||||||
|
|
||||||
## 头条号
|
## 头条号
|
||||||
|
|
||||||
我们也在头条号上创建了我们的公众号,请扫描下面的 QR 关注我们的头条号。
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## 知乎
|
||||||
|
请关注我们的知乎:https://www.zhihu.com/people/huyuchengus
|
||||||
|
|
||||||
## 快速导航
|
## 快速导航
|
||||||
|
|
||||||
在下面的表格中,我们列出了一些比较有用的 CWIKIUS 相关软件开发使用教程的导航,欢迎访问下面的链接获得更多的内容和参与讨论
|
在下面的表格中,我们列出了一些比较有用的 CWIKIUS 相关软件开发使用教程的导航,欢迎访问下面的链接获得更多的内容和参与讨论
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
## 相关文章
|
## 相关文章
|
||||||
|
|
||||||
|
- [J2EE,Java EE,Jakarta EE 命名之间的恩恩怨怨](https://www.ossez.com/t/j2ee-java-ee-jakarta-ee/14382)
|
||||||
- [Understanding the NumberFormatException in Java](https://www.baeldung.com/java-number-format-exception)
|
- [Understanding the NumberFormatException in Java](https://www.baeldung.com/java-number-format-exception)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
本模块中包含有关 Java 11 核心新增功能的的一些文章
|
本模块中包含有关 Java 11 核心新增功能的的一些文章
|
||||||
|
|
||||||
### 相关文章
|
### 相关文章
|
||||||
- [Java 8 开始新增的 Optional 类](https://www.ossez.com/t/java-8-optional/13964)
|
|
||||||
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
|
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
|
||||||
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
||||||
- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
|
- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>${guava.version}</version>
|
<version>${version.guava}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mock-server</groupId>
|
<groupId>org.mock-server</groupId>
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ This module contains articles about Java 11 core features
|
|||||||
- [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference)
|
- [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference)
|
||||||
- [Benchmark JDK Collections vs Eclipse Collections](https://www.baeldung.com/jdk-collections-vs-eclipse-collections)
|
- [Benchmark JDK Collections vs Eclipse Collections](https://www.baeldung.com/jdk-collections-vs-eclipse-collections)
|
||||||
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
|
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>${guava.version}</version>
|
<version>${version.guava}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
本模块中包含有关 Java 8 核心新增功能特性的一些文章。
|
本模块中包含有关 Java 8 核心新增功能特性的一些文章。
|
||||||
|
|
||||||
### 相关文章
|
### 相关文章
|
||||||
|
|
||||||
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
|
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
|
||||||
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
|
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
|
||||||
- [Guide to Java BiFunction Interface](https://www.baeldung.com/java-bifunction-interface)
|
- [Guide to Java BiFunction Interface](https://www.baeldung.com/java-bifunction-interface)
|
||||||
- [Interface With Default Methods vs Abstract Class](https://www.baeldung.com/java-interface-default-method-vs-abstract-class)
|
- [Interface With Default Methods vs Abstract Class](https://www.baeldung.com/java-interface-default-method-vs-abstract-class)
|
||||||
- [Convert Between Byte Array and UUID in Java](https://www.baeldung.com/java-byte-array-to-uuid)
|
- [Convert Between Byte Array and UUID in Java](https://www.baeldung.com/java-byte-array-to-uuid)
|
||||||
- [Create a Simple “Rock-Paper-Scissors” Game in Java](https://www.baeldung.com/java-rock-paper-scissors)
|
- [Create a Simple “Rock-Paper-Scissors” Game in Java](https://www.baeldung.com/java-rock-paper-scissors)
|
||||||
|
- [Java 8 开始新增的 Optional 类](https://www.ossez.com/t/java-8-optional/13964)
|
||||||
- [[<-- Java 8 核心(第 1 部分)]](/core-java-modules/core-java-8)
|
- [[<-- Java 8 核心(第 1 部分)]](/core-java-modules/core-java-8)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${version.log4j}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -71,12 +71,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${version.log4j}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
<version>${slf4j.version}</version>
|
<version>${version.slf4j}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${version.log4j}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
- [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting)
|
- [Java Localization – Formatting Messages](https://www.baeldung.com/java-localization-messages-formatting)
|
||||||
- [Java – Generate Random String](https://www.baeldung.com/java-random-string)
|
- [Java – Generate Random String](https://www.baeldung.com/java-random-string)
|
||||||
- [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions)
|
- [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions)
|
||||||
- [Java Multi-line String](https://www.baeldung.com/java-multiline-string)
|
- [Java 多行字符串](https://www.ossez.com/t/java/14049)
|
||||||
- [Java 中的 String Pool 简介](https://www.ossez.com/t/java-string-pool/14017)
|
- [Java 中的 String Pool 简介](https://www.ossez.com/t/java-string-pool/14017)
|
||||||
- [Fixing “constant string too long” Build Error](https://www.baeldung.com/java-constant-string-too-long-error)
|
- [Java “constant string too long” 编译错误](https://www.ossez.com/t/java-constant-string-too-long/14048)
|
||||||
- [Java 对象如何安全的 toString](https://www.ossez.com/t/java-tostring/14000)
|
- [Java 对象如何安全的 toString](https://www.ossez.com/t/java-tostring/14000)
|
||||||
- [编程常用的几种字符编码](https://www.ossez.com/t/topic/14022)
|
- [编程常用的几种字符编码](https://www.ossez.com/t/topic/14022)
|
||||||
|
|||||||
+9
-4
@@ -2,14 +2,13 @@ package com.ossez.multiline;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class MultiLineStringUnitTest {
|
public class MultiLineStringUnitTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCompareMultiLineStrings_thenTheyAreAllTheSame() throws IOException {
|
public void whenCompareMultiLineStrings_thenTheyAreAllTheSame() throws IOException {
|
||||||
MultiLineString ms = new MultiLineString();
|
MultiLineString ms = new MultiLineString();
|
||||||
@@ -17,7 +16,13 @@ public class MultiLineStringUnitTest {
|
|||||||
assertEquals(ms.stringJoin(), ms.stringBuilder());
|
assertEquals(ms.stringJoin(), ms.stringBuilder());
|
||||||
assertEquals(ms.stringBuilder(), ms.guavaJoiner());
|
assertEquals(ms.stringBuilder(), ms.guavaJoiner());
|
||||||
assertEquals(ms.guavaJoiner(), ms.loadFromFile());
|
assertEquals(ms.guavaJoiner(), ms.loadFromFile());
|
||||||
assertEquals(ms.loadFromFile(), ms.textBlocks());
|
|
||||||
|
// Due to JDK version, we cannot test TestBlocks
|
||||||
|
// assertEquals(ms.loadFromFile(), ms.textBlocks());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void newlineInOS() throws IOException {
|
||||||
|
System.out.println(System.lineSeparator());
|
||||||
|
System.out.println(System.getProperty("line.separator"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
*.class
|
||||||
|
|
||||||
|
0.*
|
||||||
|
|
||||||
|
#folders#
|
||||||
|
/target
|
||||||
|
/neoDb*
|
||||||
|
/data
|
||||||
|
/src/main/webapp/WEB-INF/classes
|
||||||
|
*/META-INF/*
|
||||||
|
.resourceCache
|
||||||
|
|
||||||
|
# Packaged files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
|
||||||
|
# Files generated by integration tests
|
||||||
|
*.txt
|
||||||
|
backup-pom.xml
|
||||||
|
/bin/
|
||||||
|
/temp
|
||||||
|
|
||||||
|
#IntelliJ specific
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
## Java 核心
|
||||||
|
|
||||||
|
本模块中包含有关 Java 核心新增功能特性的一些文章。
|
||||||
|
|
||||||
|
### 相关文章:
|
||||||
|
- [Java Preview Features](https://www.baeldung.com/java-preview-features)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?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</artifactId>
|
||||||
|
<name>core-java</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ossez.core-java-modules</groupId>
|
||||||
|
<artifactId>core-java-modules</artifactId>
|
||||||
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
<version>${commons-collections4.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- test scoped -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>core-java-8</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- util -->
|
||||||
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
|
<!-- testing -->
|
||||||
|
<assertj.version>3.6.1</assertj.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.ossez.features;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
|
||||||
|
public class Template {
|
||||||
|
|
||||||
|
private static final Clock clock = Clock.fixed(Instant.parse("2016-10-09T15:10:30.00Z"), ZoneId.of("UTC"));
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="TRACE">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package com.ossez.features.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoField;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class CurrentDateTimeUnitTest {
|
||||||
|
|
||||||
|
private static final Clock clock = Clock.fixed(Instant.parse("2016-10-09T15:10:30.00Z"), ZoneId.of("UTC"));
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnCurrentDate() {
|
||||||
|
final LocalDate now = LocalDate.now(clock);
|
||||||
|
|
||||||
|
assertEquals(9, now.get(ChronoField.DAY_OF_MONTH));
|
||||||
|
assertEquals(10, now.get(ChronoField.MONTH_OF_YEAR));
|
||||||
|
assertEquals(2016, now.get(ChronoField.YEAR));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnCurrentTime() {
|
||||||
|
final LocalTime now = LocalTime.now(clock);
|
||||||
|
|
||||||
|
assertEquals(15, now.get(ChronoField.HOUR_OF_DAY));
|
||||||
|
assertEquals(10, now.get(ChronoField.MINUTE_OF_HOUR));
|
||||||
|
assertEquals(30, now.get(ChronoField.SECOND_OF_MINUTE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnCurrentTimestamp() {
|
||||||
|
final Instant now = Instant.now(clock);
|
||||||
|
|
||||||
|
assertEquals(clock.instant().getEpochSecond(), now.getEpochSecond());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
*.class
|
||||||
|
|
||||||
|
#folders#
|
||||||
|
/target
|
||||||
|
/neoDb*
|
||||||
|
/data
|
||||||
|
/src/main/webapp/WEB-INF/classes
|
||||||
|
*/META-INF/*
|
||||||
|
|
||||||
|
# Packaged files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
@@ -15,10 +15,11 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
<module>core-java</module>
|
||||||
<module>core-java-8</module>
|
<module>core-java-8</module>
|
||||||
<module>core-java-8-2</module>
|
<module>core-java-8-2</module>
|
||||||
<module>core-java-11</module>
|
<module>core-java-11</module>
|
||||||
<module>core-java-11-2</module>
|
<!-- <module>core-java-11-2</module>-->
|
||||||
<module>core-java-annotations</module>
|
<module>core-java-annotations</module>
|
||||||
<module>core-java-collections</module>
|
<module>core-java-collections</module>
|
||||||
<module>core-java-collections-2</module>
|
<module>core-java-collections-2</module>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>parent-boot-2</artifactId>
|
<artifactId>parent-boot-2</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
<name>parent-boot-2</name>
|
<name>parent-boot-2</name>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<description>Parent for all Spring Boot 2 modules</description>
|
<description>Parent for all Spring Boot 2 modules</description>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ossez</groupId>
|
<groupId>com.ossez</groupId>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.ossez</groupId>
|
||||||
<artifactId>persistence-modules</artifactId>
|
<artifactId>persistence-modules</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
<name>hibernate5</name>
|
<name>hibernate5</name>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.ossez</groupId>
|
||||||
<artifactId>persistence-modules</artifactId>
|
<artifactId>persistence-modules</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
+69
-57
@@ -9,70 +9,82 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ossez</groupId>
|
<groupId>com.ossez</groupId>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>activejdbc</module>
|
<module>activejdbc</module>
|
||||||
<module>apache-cayenne</module>
|
<!-- <module>apache-cayenne</module>-->
|
||||||
<module>core-java-persistence</module>
|
<!-- <module>core-java-persistence</module>-->
|
||||||
<module>deltaspike</module>
|
<!-- <module>deltaspike</module>-->
|
||||||
<module>elasticsearch</module>
|
<!-- <module>elasticsearch</module>-->
|
||||||
<module>flyway</module>
|
<!-- <module>flyway</module>-->
|
||||||
<module>hbase</module>
|
<!-- <module>hbase</module>-->
|
||||||
<module>hibernate5</module>
|
<!-- <module>hibernate5</module>-->
|
||||||
<module>hibernate-mapping</module> <!-- long running -->
|
<!-- <module>hibernate-mapping</module> <!– long running –>-->
|
||||||
<module>hibernate-ogm</module>
|
<!-- <module>hibernate-ogm</module>-->
|
||||||
<module>hibernate-annotations</module>
|
<!-- <module>hibernate-annotations</module>-->
|
||||||
<module>hibernate-jpa</module>
|
<!-- <module>hibernate-jpa</module>-->
|
||||||
<module>hibernate-queries</module>
|
<!-- <module>hibernate-queries</module>-->
|
||||||
<module>hibernate-enterprise</module>
|
<!-- <module>hibernate-enterprise</module>-->
|
||||||
<module>influxdb</module>
|
<!-- <module>influxdb</module>-->
|
||||||
<module>java-cassandra</module>
|
<!-- <module>java-cassandra</module>-->
|
||||||
<module>java-cockroachdb</module>
|
<!-- <module>java-cockroachdb</module>-->
|
||||||
<module>java-jdbi</module>
|
<!-- <module>java-jdbi</module>-->
|
||||||
<module>java-jpa</module> <!-- long running -->
|
<!-- <module>java-jpa</module> <!– long running –>-->
|
||||||
<module>java-jpa-2</module> <!-- long running -->
|
<!-- <module>java-jpa-2</module> <!– long running –>-->
|
||||||
<module>java-mongodb</module> <!-- long running -->
|
<!-- <module>java-mongodb</module> <!– long running –>-->
|
||||||
<module>jnosql</module> <!-- long running -->
|
<!-- <module>jnosql</module> <!– long running –>-->
|
||||||
<module>jpa-hibernate-cascade-type</module>
|
<!-- <module>jpa-hibernate-cascade-type</module>-->
|
||||||
<module>liquibase</module>
|
<!-- <module>liquibase</module>-->
|
||||||
<module>orientdb</module>
|
<!-- <module>orientdb</module>-->
|
||||||
<module>persistence-libraries</module>
|
<!-- <module>persistence-libraries</module>-->
|
||||||
<module>querydsl</module>
|
<!-- <module>querydsl</module>-->
|
||||||
<module>r2dbc</module>
|
<!-- <module>r2dbc</module>-->
|
||||||
<module>redis</module>
|
<!-- <module>redis</module>-->
|
||||||
<!-- <module>sirix</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
|
<!-- <module>sirix</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
|
||||||
<module>solr</module>
|
<!-- <module>solr</module>-->
|
||||||
<module>spring-boot-persistence-2</module>
|
<!-- <module>spring-boot-persistence-2</module>-->
|
||||||
<module>spring-boot-mysql</module>
|
<!-- <module>spring-boot-mysql</module>-->
|
||||||
<module>spring-boot-persistence</module>
|
<!-- <module>spring-boot-persistence</module>-->
|
||||||
<module>spring-boot-persistence-h2</module>
|
<!-- <module>spring-boot-persistence-h2</module>-->
|
||||||
<module>spring-boot-persistence-mongodb</module>
|
<!-- <module>spring-boot-persistence-mongodb</module>-->
|
||||||
<module>spring-data-cassandra</module>
|
<!-- <module>spring-boot-persistence-mongodb-2</module>-->
|
||||||
<module>spring-data-cassandra-reactive</module>
|
<!-- <module>spring-data-arangodb</module>-->
|
||||||
<module>spring-data-couchbase-2</module>
|
<!-- <module>spring-data-cassandra</module>-->
|
||||||
<module>spring-data-dynamodb</module>
|
<!-- <module>spring-data-cassandra-test</module>-->
|
||||||
<module>spring-data-eclipselink</module>
|
<!-- <module>spring-data-cassandra-reactive</module>-->
|
||||||
<module>spring-data-elasticsearch</module>
|
<!-- <module>spring-data-cosmosdb</module>-->
|
||||||
<module>spring-data-gemfire</module>
|
<!-- <module>spring-data-couchbase-2</module>-->
|
||||||
<module>spring-data-geode</module>
|
<!-- <module>spring-data-dynamodb</module>-->
|
||||||
<module>spring-data-jpa</module>
|
<!-- <module>spring-data-eclipselink</module>-->
|
||||||
<module>spring-data-jpa-2</module>
|
<!-- <module>spring-data-elasticsearch</module>-->
|
||||||
<module>spring-data-jpa-3</module>
|
<!-- <!– <module>spring-data-gemfire</module> Fixing in JAVA-11854 –>-->
|
||||||
<module>spring-data-jpa-4</module>
|
<!-- <module>spring-data-geode</module>-->
|
||||||
<module>spring-data-keyvalue</module>
|
<!-- <module>spring-data-jpa-annotations</module>-->
|
||||||
<module>spring-data-mongodb</module>
|
<!-- <module>spring-data-jpa-crud</module>-->
|
||||||
<module>spring-data-neo4j</module>
|
<!-- <module>spring-data-jpa-crud-2</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-enterprise</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-enterprise-2</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-filtering</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-query</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-query-2</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-query-3</module>-->
|
||||||
|
<!-- <module>spring-data-jpa-repo</module>-->
|
||||||
|
<module>spring-data-jpa-repo-2</module>
|
||||||
|
<!-- <module>spring-data-keyvalue</module>-->
|
||||||
|
<!-- <module>spring-data-mongodb</module>-->
|
||||||
|
<!-- <module>spring-data-neo4j</module>-->
|
||||||
<module>spring-data-redis</module>
|
<module>spring-data-redis</module>
|
||||||
<module>spring-data-solr</module>
|
<!-- <module>spring-data-solr</module>-->
|
||||||
<module>spring-hibernate-3</module>
|
<!-- <module>spring-hibernate-3</module>-->
|
||||||
<module>spring-hibernate-5</module> <!-- long running -->
|
<!-- <module>spring-hibernate-5</module> <!– long running –>-->
|
||||||
<module>spring-hibernate4</module>
|
<!-- <module>spring-hibernate4</module>-->
|
||||||
<module>spring-jpa</module>
|
<!-- <module>spring-jpa</module>-->
|
||||||
<!-- <module>spring-mybatis</module> --> <!-- needs fixing in BAEL-9021 -->
|
<!-- <module>spring-mybatis</module> --> <!-- needs fixing in BAEL-9021 -->
|
||||||
<module>spring-persistence-simple</module>
|
<!-- <module>spring-persistence-simple</module>-->
|
||||||
<module>spring-persistence-simple-2</module>
|
<!-- <module>spring-persistence-simple-2</module>-->
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
## Spring Data JPA - Repositories
|
||||||
|
|
||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
|
||||||
|
- [Performance Difference Between save() and saveAll() in Spring Data](https://www.baeldung.com/spring-data-save-saveall)
|
||||||
|
- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries)
|
||||||
|
- [How to Access EntityManager with Spring Data](https://www.baeldung.com/spring-data-entitymanager)
|
||||||
|
- More articles: [[<-- prev]](../spring-data-jpa-repo)
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?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-data-jpa-repo-2</artifactId>
|
||||||
|
<name>spring-data-jpa-repo-2</name>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ossez</groupId>
|
||||||
|
<artifactId>parent-boot-2</artifactId>
|
||||||
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-2</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.persistence</groupId>
|
||||||
|
<artifactId>javax.persistence-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>${version.guava}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.customrepository;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class CustomRepositoryApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(CustomRepositoryApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.customrepository.model;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
User user = (User) o;
|
||||||
|
return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(email, user.email);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, email);
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.customrepository.repository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.customrepository.model.User;
|
||||||
|
|
||||||
|
public interface CustomUserRepository {
|
||||||
|
|
||||||
|
User customFindMethod(Long id);
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.customrepository.repository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.customrepository.model.User;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class CustomUserRepositoryImpl implements CustomUserRepository {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User customFindMethod(Long id) {
|
||||||
|
return (User) entityManager.createQuery("FROM User u WHERE u.id = :id")
|
||||||
|
.setParameter("id", id)
|
||||||
|
.getSingleResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void postConstruct() {
|
||||||
|
Objects.requireNonNull(entityManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.customrepository.repository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.customrepository.model.User;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface UserRepository extends JpaRepository<User, Long>, CustomUserRepository {
|
||||||
|
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.like;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class LikeApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LikeApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.like.model;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Movie {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||||
|
private Long id;
|
||||||
|
private String title;
|
||||||
|
private String director;
|
||||||
|
private String rating;
|
||||||
|
private int duration;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDirector() {
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDirector(String director) {
|
||||||
|
this.director = director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRating() {
|
||||||
|
return rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRating(String rating) {
|
||||||
|
this.rating = rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(int duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.like.repository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.like.model.Movie;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MovieRepository extends CrudRepository<Movie, Long> {
|
||||||
|
|
||||||
|
List<Movie> findByTitleContaining(String title);
|
||||||
|
|
||||||
|
List<Movie> findByTitleLike(String title);
|
||||||
|
|
||||||
|
List<Movie> findByTitleContains(String title);
|
||||||
|
|
||||||
|
List<Movie> findByTitleIsContaining(String title);
|
||||||
|
|
||||||
|
List<Movie> findByRatingStartsWith(String rating);
|
||||||
|
|
||||||
|
List<Movie> findByDirectorEndsWith(String director);
|
||||||
|
|
||||||
|
List<Movie> findByTitleContainingIgnoreCase(String title);
|
||||||
|
|
||||||
|
List<Movie> findByRatingNotContaining(String rating);
|
||||||
|
|
||||||
|
List<Movie> findByDirectorNotLike(String director);
|
||||||
|
|
||||||
|
@Query("SELECT m FROM Movie m WHERE m.title LIKE %:title%")
|
||||||
|
List<Movie> searchByTitleLike(@Param("title") String title);
|
||||||
|
|
||||||
|
@Query("SELECT m FROM Movie m WHERE m.rating LIKE ?1%")
|
||||||
|
List<Movie> searchByRatingStartsWith(String rating);
|
||||||
|
|
||||||
|
//Escaping works in SpringBoot >= 2.4.1
|
||||||
|
//@Query("SELECT m FROM Movie m WHERE m.director LIKE %?#{escape([0])} escape ?#{escapeCharacter()}")
|
||||||
|
@Query("SELECT m FROM Movie m WHERE m.director LIKE %:#{[0]}")
|
||||||
|
List<Movie> searchByDirectorEndsWith(String director);
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Book {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
public Book(final String title, final String author) {
|
||||||
|
this.title = title;
|
||||||
|
this.author = author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Book() {
|
||||||
|
}
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class BookApplication {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(BookApplication.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BookRepository bookRepository;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(BookApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
|
public void executePerformanceBenchmark() {
|
||||||
|
|
||||||
|
int bookCount = 10000;
|
||||||
|
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < bookCount; i++) {
|
||||||
|
bookRepository.save(new Book("Book " + i, "Author " + i));
|
||||||
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
bookRepository.deleteAll();
|
||||||
|
|
||||||
|
LOGGER.debug("It took {}ms to execute save() for {} books.", (end - start), bookCount);
|
||||||
|
|
||||||
|
List<Book> bookList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < bookCount; i++) {
|
||||||
|
bookList.add(new Book("Book " + i, "Author " + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
bookRepository.saveAll(bookList);
|
||||||
|
end = System.currentTimeMillis();
|
||||||
|
|
||||||
|
LOGGER.debug("It took {}ms to execute saveAll() with {}} books.", (end - start), bookCount);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface BookRepository extends JpaRepository<Book, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance.repository;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Foo implements Serializable {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Foo() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Foo(final String name) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(final long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
final Foo other = (Foo) obj;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("Foo [name=").append(name).append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance.repository;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class FooService implements IFooService {
|
||||||
|
@Autowired
|
||||||
|
private IFooDAO dao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Foo create(Foo foo) {
|
||||||
|
return dao.save(foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
public interface IFooDAO extends JpaRepository<Foo, Long> {
|
||||||
|
|
||||||
|
Foo findByName(String name);
|
||||||
|
|
||||||
|
@Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)")
|
||||||
|
Foo retrieveByName(@Param("name") String name);
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance.repository;
|
||||||
|
|
||||||
|
public interface IFooService {
|
||||||
|
Foo create(Foo foo);
|
||||||
|
}
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.saveperformance.repository;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||||
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource("classpath:persistence.properties")
|
||||||
|
@ComponentScan("com.baeldung.spring.data.persistence.repository")
|
||||||
|
//@ImportResource("classpath*:*springDataConfig.xml")
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@EnableJpaRepositories(basePackages = "com.baeldung.spring.data.persistence.repository")
|
||||||
|
public class PersistenceConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Environment env;
|
||||||
|
|
||||||
|
public PersistenceConfig() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
|
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
em.setDataSource(dataSource());
|
||||||
|
em.setPackagesToScan("com.baeldung.spring.data.persistence.repository");
|
||||||
|
|
||||||
|
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||||
|
em.setJpaVendorAdapter(vendorAdapter);
|
||||||
|
em.setJpaProperties(additionalProperties());
|
||||||
|
|
||||||
|
return em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DataSource dataSource() {
|
||||||
|
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||||
|
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
|
||||||
|
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
|
||||||
|
dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user")));
|
||||||
|
dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass")));
|
||||||
|
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager transactionManager() {
|
||||||
|
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||||
|
transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
|
||||||
|
|
||||||
|
return transactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
|
||||||
|
return new PersistenceExceptionTranslationPostProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Properties additionalProperties() {
|
||||||
|
final Properties hibernateProperties = new Properties();
|
||||||
|
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||||
|
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||||
|
|
||||||
|
return hibernateProperties;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||||
|
spring.datasource.username=sa
|
||||||
|
spring.datasource.password=sa
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="DEBUG">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# jdbc.X
|
||||||
|
jdbc.driverClassName=org.h2.Driver
|
||||||
|
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||||
|
jdbc.user=sa
|
||||||
|
jdbc.pass=sa
|
||||||
|
|
||||||
|
# hibernate.X
|
||||||
|
hibernate.hbm2ddl.auto=create-drop
|
||||||
|
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/data/jpa
|
||||||
|
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
|
||||||
|
>
|
||||||
|
<jpa:repositories base-package="com.baeldung.spring.data.persistence.repository"/>
|
||||||
|
</beans>
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.customrepository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.customrepository.model.User;
|
||||||
|
import com.baeldung.spring.data.persistence.customrepository.repository.UserRepository;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = CustomRepositoryApplication.class)
|
||||||
|
class CustomRepositoryUnitTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenCustomRepository_whenInvokeCustomFindMethod_thenEntityIsFound() {
|
||||||
|
User user = new User();
|
||||||
|
user.setEmail("foo@gmail.com");
|
||||||
|
user.setName("userName");
|
||||||
|
|
||||||
|
User persistedUser = userRepository.save(user);
|
||||||
|
|
||||||
|
assertEquals(persistedUser, userRepository.customFindMethod(user.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.like;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.like.model.Movie;
|
||||||
|
import com.baeldung.spring.data.persistence.like.repository.MovieRepository;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@Sql(scripts = { "/test-movie-data.sql" })
|
||||||
|
@SpringBootTest(classes = LikeApplication.class)
|
||||||
|
@Sql(scripts = "/test-movie-cleanup.sql", executionPhase = AFTER_TEST_METHOD)
|
||||||
|
public class MovieRepositoryIntegrationTest {
|
||||||
|
@Autowired
|
||||||
|
private MovieRepository movieRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPartialTitle_WhenFindByTitleContaining_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.findByTitleContaining("in");
|
||||||
|
assertEquals(3, results.size());
|
||||||
|
|
||||||
|
results = movieRepository.findByTitleLike("%in%");
|
||||||
|
assertEquals(3, results.size());
|
||||||
|
|
||||||
|
results = movieRepository.findByTitleIsContaining("in");
|
||||||
|
assertEquals(3, results.size());
|
||||||
|
|
||||||
|
results = movieRepository.findByTitleContains("in");
|
||||||
|
assertEquals(3, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStartOfRating_WhenFindByRatingStartsWith_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.findByRatingStartsWith("PG");
|
||||||
|
assertEquals(6, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLastName_WhenFindByDirectorEndsWith_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.findByDirectorEndsWith("Burton");
|
||||||
|
assertEquals(1, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPartialTitle_WhenFindByTitleContainingIgnoreCase_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.findByTitleContainingIgnoreCase("the");
|
||||||
|
assertEquals(2, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPartialTitle_WhenSearchByTitleLike_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.searchByTitleLike("in");
|
||||||
|
assertEquals(3, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStartOfRating_SearchFindByRatingStartsWith_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.searchByRatingStartsWith("PG");
|
||||||
|
assertEquals(6, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLastName_WhenSearchByDirectorEndsWith_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.searchByDirectorEndsWith("Burton");
|
||||||
|
assertEquals(1, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPartialRating_findByRatingNotContaining_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.findByRatingNotContaining("PG");
|
||||||
|
assertEquals(1, results.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPartialDirector_WhenFindByDirectorNotLike_ThenMoviesShouldReturn() {
|
||||||
|
List<Movie> results = movieRepository.findByDirectorNotLike("An%");
|
||||||
|
assertEquals(5, results.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package com.baeldung.spring.data.persistence.repository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.persistence.saveperformance.repository.Foo;
|
||||||
|
import com.baeldung.spring.data.persistence.saveperformance.repository.IFooService;
|
||||||
|
import com.baeldung.spring.data.persistence.saveperformance.repository.PersistenceConfig;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@ContextConfiguration(classes = PersistenceConfig.class)
|
||||||
|
public class FooServiceIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IFooService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
@Test(expected = DataIntegrityViolationException.class)
|
||||||
|
public final void whenInvalidEntityIsCreated_thenDataException() {
|
||||||
|
service.create(new Foo());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?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>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DELETE FROM Movie;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(1, 'Godzilla: King of the Monsters', ' Michael Dougherty', 'PG-13', 132);
|
||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(2, 'Avengers: Endgame', 'Anthony Russo', 'PG-13', 181);
|
||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(3, 'Captain Marvel', 'Anna Boden', 'PG-13', 123);
|
||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(4, 'Dumbo', 'Tim Burton', 'PG', 112);
|
||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(5, 'Booksmart', 'Olivia Wilde', 'R', 102);
|
||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(6, 'Aladdin', 'Guy Ritchie', 'PG', 128);
|
||||||
|
INSERT INTO movie(id, title, director, rating, duration) VALUES(7, 'The Sun Is Also a Star', 'Ry Russo-Young', 'PG-13', 100);
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
## Spring Data Redis
|
||||||
|
|
||||||
|
### 相关文章:
|
||||||
|
- [介绍 Spring Data Redis](https://www.ossez.com/t/spring-data-redis/14299)
|
||||||
|
- [PubSub Messaging with Spring Data Redis](https://www.baeldung.com/spring-data-redis-pub-sub)
|
||||||
|
- [An Introduction to Spring Data Redis Reactive](https://www.baeldung.com/spring-data-redis-reactive)
|
||||||
|
|
||||||
|
### 构建项目并且运行所有的测试
|
||||||
|
```
|
||||||
|
mvn clean install
|
||||||
|
```
|
||||||
|
|
||||||
|
### 只运行测试
|
||||||
|
```
|
||||||
|
mvn test
|
||||||
|
```
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<?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-data-redis</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>spring-data-redis</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ossez</groupId>
|
||||||
|
<artifactId>parent-boot-2</artifactId>
|
||||||
|
<version>0.0.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-2</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.projectreactor</groupId>
|
||||||
|
<artifactId>reactor-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-runner</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cglib</groupId>
|
||||||
|
<artifactId>cglib-nodep</artifactId>
|
||||||
|
<version>${cglib.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lordofthejars</groupId>
|
||||||
|
<artifactId>nosqlunit-redis</artifactId>
|
||||||
|
<version>${nosqlunit.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.kstyrc</groupId>
|
||||||
|
<artifactId>embedded-redis</artifactId>
|
||||||
|
<version>${embedded-redis.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<verbose>true</verbose>
|
||||||
|
<fork>false</fork>
|
||||||
|
<forkCount>0</forkCount>
|
||||||
|
<argLine>-Xmx1024m</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<cglib.version>3.2.4</cglib.version>
|
||||||
|
<nosqlunit.version>0.10.0</nosqlunit.version>
|
||||||
|
<embedded-redis.version>0.6</embedded-redis.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.spring.data.reactive.redis;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringRedisReactiveApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SpringRedisReactiveApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package com.baeldung.spring.data.reactive.redis.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.reactive.redis.model.Employee;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.ReactiveKeyCommands;
|
||||||
|
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.connection.ReactiveStringCommands;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedisConnectionFactory factory;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ReactiveRedisTemplate<String, Employee> reactiveRedisTemplate(ReactiveRedisConnectionFactory factory) {
|
||||||
|
Jackson2JsonRedisSerializer<Employee> serializer = new Jackson2JsonRedisSerializer<>(Employee.class);
|
||||||
|
RedisSerializationContext.RedisSerializationContextBuilder<String, Employee> builder = RedisSerializationContext.newSerializationContext(new StringRedisSerializer());
|
||||||
|
RedisSerializationContext<String, Employee> context = builder.value(serializer)
|
||||||
|
.build();
|
||||||
|
return new ReactiveRedisTemplate<>(factory, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ReactiveKeyCommands keyCommands(final ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
|
||||||
|
return reactiveRedisConnectionFactory.getReactiveConnection()
|
||||||
|
.keyCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ReactiveStringCommands stringCommands(final ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
|
||||||
|
return reactiveRedisConnectionFactory.getReactiveConnection()
|
||||||
|
.stringCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void cleanRedis() {
|
||||||
|
factory.getConnection()
|
||||||
|
.flushDb();
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.spring.data.reactive.redis.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class Employee implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1603714798906422731L;
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String department;
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.spring.data.redis;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringRedisApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SpringRedisApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package com.baeldung.spring.data.redis.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.listener.ChannelTopic;
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
|
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
|
||||||
|
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
||||||
|
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.queue.MessagePublisher;
|
||||||
|
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
|
||||||
|
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan("com.baeldung.spring.data.redis")
|
||||||
|
@EnableRedisRepositories(basePackages = "com.baeldung.spring.data.redis.repo")
|
||||||
|
@PropertySource("classpath:application.properties")
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
JedisConnectionFactory jedisConnectionFactory() {
|
||||||
|
return new JedisConnectionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate() {
|
||||||
|
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
|
||||||
|
template.setConnectionFactory(jedisConnectionFactory());
|
||||||
|
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
MessageListenerAdapter messageListener() {
|
||||||
|
return new MessageListenerAdapter(new RedisMessageSubscriber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
RedisMessageListenerContainer redisContainer() {
|
||||||
|
final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||||
|
container.setConnectionFactory(jedisConnectionFactory());
|
||||||
|
container.addMessageListener(messageListener(), topic());
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
MessagePublisher redisPublisher() {
|
||||||
|
return new RedisMessagePublisher(redisTemplate(), topic());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
ChannelTopic topic() {
|
||||||
|
return new ChannelTopic("pubsub:queue");
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.baeldung.spring.data.redis.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.springframework.data.redis.core.RedisHash;
|
||||||
|
|
||||||
|
@RedisHash("Student")
|
||||||
|
public class Student implements Serializable {
|
||||||
|
|
||||||
|
public enum Gender {
|
||||||
|
MALE, FEMALE
|
||||||
|
}
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private Gender gender;
|
||||||
|
private int grade;
|
||||||
|
|
||||||
|
public Student(String id, String name, Gender gender, int grade) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.gender = gender;
|
||||||
|
this.grade = grade;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Gender getGender() {
|
||||||
|
return gender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGender(Gender gender) {
|
||||||
|
this.gender = gender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGrade() {
|
||||||
|
return grade;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrade(int grade) {
|
||||||
|
this.grade = grade;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Student{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", gender=" + gender + ", grade=" + grade + '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package com.baeldung.spring.data.redis.queue;
|
||||||
|
|
||||||
|
public interface MessagePublisher {
|
||||||
|
|
||||||
|
void publish(final String message);
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package com.baeldung.spring.data.redis.queue;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.listener.ChannelTopic;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RedisMessagePublisher implements MessagePublisher {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private ChannelTopic topic;
|
||||||
|
|
||||||
|
public RedisMessagePublisher() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedisMessagePublisher(final RedisTemplate<String, Object> redisTemplate, final ChannelTopic topic) {
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
|
this.topic = topic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publish(final String message) {
|
||||||
|
redisTemplate.convertAndSend(topic.getTopic(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.spring.data.redis.queue;
|
||||||
|
|
||||||
|
import org.springframework.data.redis.connection.Message;
|
||||||
|
import org.springframework.data.redis.connection.MessageListener;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RedisMessageSubscriber implements MessageListener {
|
||||||
|
|
||||||
|
public static List<String> messageList = new ArrayList<String>();
|
||||||
|
|
||||||
|
public void onMessage(final Message message, final byte[] pattern) {
|
||||||
|
messageList.add(message.toString());
|
||||||
|
System.out.println("Message received: " + new String(message.getBody()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.spring.data.redis.repo;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.model.Student;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface StudentRepository extends CrudRepository<Student, String> {}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
spring.redis.host=localhost
|
||||||
|
spring.redis.port=6379
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="org.springframework" level="WARN" />
|
||||||
|
<logger name="org.springframework.transaction" level="WARN" />
|
||||||
|
|
||||||
|
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
|
||||||
|
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 855 B |
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.baeldung;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.SpringRedisApplication;
|
||||||
|
|
||||||
|
import redis.embedded.RedisServerBuilder;
|
||||||
|
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisApplication.class)
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class SpringContextTest {
|
||||||
|
|
||||||
|
private static redis.embedded.RedisServer redisServer;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startRedisServer() {
|
||||||
|
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopRedisServer() {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||||
|
}
|
||||||
|
}
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
package com.baeldung.spring.data.reactive.redis.template;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.reactive.redis.SpringRedisReactiveApplication;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.redis.connection.ReactiveKeyCommands;
|
||||||
|
import org.springframework.data.redis.connection.ReactiveStringCommands;
|
||||||
|
import org.springframework.data.redis.connection.ReactiveStringCommands.SetCommand;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.test.StepVerifier;
|
||||||
|
import redis.embedded.RedisServerBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisReactiveApplication.class)
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class RedisKeyCommandsManualTest {
|
||||||
|
|
||||||
|
private static redis.embedded.RedisServer redisServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactiveKeyCommands keyCommands;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactiveStringCommands stringCommands;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startRedisServer() throws IOException {
|
||||||
|
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopRedisServer() throws IOException {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFluxOfKeys_whenPerformOperations_thenPerformOperations() {
|
||||||
|
Flux<String> keys = Flux.just("key1", "key2", "key3", "key4");
|
||||||
|
|
||||||
|
Flux<SetCommand> generator = keys.map(String::getBytes)
|
||||||
|
.map(ByteBuffer::wrap)
|
||||||
|
.map(key -> SetCommand.set(key)
|
||||||
|
.value(key));
|
||||||
|
|
||||||
|
StepVerifier.create(stringCommands.set(generator))
|
||||||
|
.expectNextCount(4L)
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
|
Mono<Long> keyCount = keyCommands.keys(ByteBuffer.wrap("key*".getBytes()))
|
||||||
|
.flatMapMany(Flux::fromIterable)
|
||||||
|
.count();
|
||||||
|
|
||||||
|
StepVerifier.create(keyCount)
|
||||||
|
.expectNext(4L)
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
package com.baeldung.spring.data.reactive.redis.template;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.reactive.redis.SpringRedisReactiveApplication;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.redis.core.ReactiveListOperations;
|
||||||
|
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.test.StepVerifier;
|
||||||
|
import redis.embedded.RedisServerBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisReactiveApplication.class)
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class RedisTemplateListOpsManualTest {
|
||||||
|
|
||||||
|
private static final String LIST_NAME = "demo_list";
|
||||||
|
private static redis.embedded.RedisServer redisServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactiveStringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
private ReactiveListOperations<String, String> reactiveListOps;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startRedisServer() throws IOException {
|
||||||
|
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopRedisServer() throws IOException {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
reactiveListOps = redisTemplate.opsForList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenListAndValues_whenLeftPushAndLeftPop_thenLeftPushAndLeftPop() {
|
||||||
|
Mono<Long> lPush = reactiveListOps.leftPushAll(LIST_NAME, "first", "second")
|
||||||
|
.log("Pushed");
|
||||||
|
|
||||||
|
StepVerifier.create(lPush)
|
||||||
|
.expectNext(2L)
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
|
Mono<String> lPop = reactiveListOps.leftPop(LIST_NAME)
|
||||||
|
.log("Popped");
|
||||||
|
|
||||||
|
StepVerifier.create(lPop)
|
||||||
|
.expectNext("second")
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+93
@@ -0,0 +1,93 @@
|
|||||||
|
package com.baeldung.spring.data.reactive.redis.template;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ReactiveValueOperations;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.reactive.redis.SpringRedisReactiveApplication;
|
||||||
|
import com.baeldung.spring.data.reactive.redis.model.Employee;
|
||||||
|
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.test.StepVerifier;
|
||||||
|
import redis.embedded.RedisServerBuilder;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisReactiveApplication.class)
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class RedisTemplateValueOpsManualTest {
|
||||||
|
|
||||||
|
private static redis.embedded.RedisServer redisServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReactiveRedisTemplate<String, Employee> redisTemplate;
|
||||||
|
|
||||||
|
private ReactiveValueOperations<String, Employee> reactiveValueOps;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startRedisServer() throws IOException {
|
||||||
|
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopRedisServer() throws IOException {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
reactiveValueOps = redisTemplate.opsForValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmployee_whenSet_thenSet() {
|
||||||
|
|
||||||
|
Mono<Boolean> result = reactiveValueOps.set("123", new Employee("123", "Bill", "Accounts"));
|
||||||
|
|
||||||
|
StepVerifier.create(result)
|
||||||
|
.expectNext(true)
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmployeeId_whenGet_thenReturnsEmployee() {
|
||||||
|
|
||||||
|
Mono<Employee> fetchedEmployee = reactiveValueOps.get("123");
|
||||||
|
|
||||||
|
StepVerifier.create(fetchedEmployee)
|
||||||
|
.expectNext(new Employee("123", "Bill", "Accounts"))
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenEmployee_whenSetWithExpiry_thenSetsWithExpiryTime() throws InterruptedException {
|
||||||
|
|
||||||
|
Mono<Boolean> result = reactiveValueOps.set("129", new Employee("129", "John", "Programming"), Duration.ofSeconds(1));
|
||||||
|
|
||||||
|
Mono<Employee> fetchedEmployee = reactiveValueOps.get("129");
|
||||||
|
|
||||||
|
StepVerifier.create(result)
|
||||||
|
.expectNext(true)
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
|
Thread.sleep(2000L);
|
||||||
|
|
||||||
|
StepVerifier.create(fetchedEmployee)
|
||||||
|
.expectNextCount(0L)
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package com.baeldung.spring.data.redis;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
|
||||||
|
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import redis.embedded.RedisServerBuilder;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisApplication.class)
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class RedisMessageListenerManualTest {
|
||||||
|
|
||||||
|
private static redis.embedded.RedisServer redisServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisMessagePublisher redisMessagePublisher;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startRedisServer() {
|
||||||
|
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopRedisServer() {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnMessage() throws Exception {
|
||||||
|
String message = "Message " + UUID.randomUUID();
|
||||||
|
redisMessagePublisher.publish(message);
|
||||||
|
Thread.sleep(1000);
|
||||||
|
assertTrue(RedisMessageSubscriber.messageList.get(0).contains(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
package com.baeldung.spring.data.redis.repo;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.config.RedisConfig;
|
||||||
|
import com.baeldung.spring.data.redis.model.Student;
|
||||||
|
|
||||||
|
import redis.embedded.RedisServerBuilder;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = RedisConfig.class)
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class StudentRepositoryManualTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StudentRepository studentRepository;
|
||||||
|
|
||||||
|
private static redis.embedded.RedisServer redisServer;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startRedisServer() throws IOException {
|
||||||
|
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopRedisServer() throws IOException {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSavingStudent_thenAvailableOnRetrieval() throws Exception {
|
||||||
|
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
|
||||||
|
studentRepository.save(student);
|
||||||
|
final Student retrievedStudent = studentRepository.findById(student.getId()).get();
|
||||||
|
assertEquals(student.getId(), retrievedStudent.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUpdatingStudent_thenAvailableOnRetrieval() throws Exception {
|
||||||
|
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
|
||||||
|
studentRepository.save(student);
|
||||||
|
student.setName("Richard Watson");
|
||||||
|
studentRepository.save(student);
|
||||||
|
final Student retrievedStudent = studentRepository.findById(student.getId()).get();
|
||||||
|
assertEquals(student.getName(), retrievedStudent.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSavingStudents_thenAllShouldAvailableOnRetrieval() throws Exception {
|
||||||
|
final Student engStudent = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
|
||||||
|
final Student medStudent = new Student("Med2015001", "Gareth Houston", Student.Gender.MALE, 2);
|
||||||
|
studentRepository.save(engStudent);
|
||||||
|
studentRepository.save(medStudent);
|
||||||
|
List<Student> students = new ArrayList<>();
|
||||||
|
studentRepository.findAll().forEach(students::add);
|
||||||
|
assertEquals(students.size(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenDeletingStudent_thenNotAvailableOnRetrieval() throws Exception {
|
||||||
|
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
|
||||||
|
studentRepository.save(student);
|
||||||
|
studentRepository.deleteById(student.getId());
|
||||||
|
final Student retrievedStudent = studentRepository.findById(student.getId()).orElse(null);
|
||||||
|
assertNull(retrievedStudent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,12 +40,13 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>core-java-modules</module>
|
<module>core-java-modules</module>
|
||||||
<!-- <module>jackson-modules</module>-->
|
<!-- <module>jackson-modules</module>-->
|
||||||
<!-- <module>jackson-simple</module>-->
|
<!-- <module>jackson-simple</module>-->
|
||||||
<!-- <module>parent-java</module>-->
|
<!-- <module>parent-java</module>-->
|
||||||
|
<module>persistence-modules</module>
|
||||||
<module>testing-modules</module>
|
<module>testing-modules</module>
|
||||||
<module>toolkits</module>
|
<module>toolkits</module>
|
||||||
<!-- <module>xml</module>-->
|
<!-- <module>xml</module>-->
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -55,9 +56,9 @@
|
|||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|
||||||
<!-- Logging -->
|
<!-- Logging -->
|
||||||
<slf4j.version>1.7.30</slf4j.version>
|
<version.slf4j>1.7.36</version.slf4j>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
<version.log4j>1.2.17</version.log4j>
|
||||||
<log4j2.version>2.2</log4j2.version>
|
<version.log4j2>2.18.0</version.log4j2>
|
||||||
|
|
||||||
<!-- APACHE COMMONS-->
|
<!-- APACHE COMMONS-->
|
||||||
<commons-io.version>2.8.0</commons-io.version>
|
<commons-io.version>2.8.0</commons-io.version>
|
||||||
@@ -71,7 +72,7 @@
|
|||||||
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
|
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
|
||||||
|
|
||||||
<!-- UTILS -->
|
<!-- UTILS -->
|
||||||
<guava.version>31.1-jre</guava.version>
|
<version.guava>31.1-jre</version.guava>
|
||||||
|
|
||||||
<!-- Hibernate / JPA -->
|
<!-- Hibernate / JPA -->
|
||||||
<hibernate.version>4.3.5.Final</hibernate.version>
|
<hibernate.version>4.3.5.Final</hibernate.version>
|
||||||
@@ -108,7 +109,7 @@
|
|||||||
<moneta.version>1.3</moneta.version>
|
<moneta.version>1.3</moneta.version>
|
||||||
<jmh-core.version>1.33</jmh-core.version>
|
<jmh-core.version>1.33</jmh-core.version>
|
||||||
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
|
||||||
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>3.0.0-M8</maven-surefire-plugin.version>
|
||||||
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
|
||||||
<logback-classic.version>1.2.5</logback-classic.version>
|
<logback-classic.version>1.2.5</logback-classic.version>
|
||||||
<rest-assured.version>3.1.1</rest-assured.version>
|
<rest-assured.version>3.1.1</rest-assured.version>
|
||||||
@@ -308,6 +309,16 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>package</defaultGoal>
|
<defaultGoal>package</defaultGoal>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@@ -320,7 +331,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.12.4</version>
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<skipTests>true</skipTests>
|
<skipTests>true</skipTests>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
/target/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
## Spring Boot 测试
|
||||||
|
|
||||||
|
本模块中包含了有关如何在 Spring Boot 中进行测试和在测试中遇到的一些问题和解决的文章。
|
||||||
|
|
||||||
|
- [Testing with Spring and Spock](https://www.baeldung.com/spring-spock-testing)
|
||||||
|
- [Exclude Auto-Configuration Classes in Spring Boot Tests](https://www.baeldung.com/spring-boot-exclude-auto-configuration-test)
|
||||||
|
- [Embedded Redis Server with Spring Boot Test](https://www.baeldung.com/spring-embedded-redis)
|
||||||
|
- [Testing Spring Boot @ConfigurationProperties](https://www.baeldung.com/spring-boot-testing-configurationproperties)
|
||||||
|
- [Prevent ApplicationRunner or CommandLineRunner Beans From Executing During Junit Testing](https://www.baeldung.com/spring-junit-prevent-runner-beans-testing-execution)
|
||||||
|
- [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing)
|
||||||
|
- [解决在 Spring Boot 中运行 JUnit 测试遇到的 NoSuchMethodError 错误](https://www.ossez.com/t/spring-boot-junit-nosuchmethoderror/14066)
|
||||||
|
- More articles: [[more -->]](../spring-boot-testing-2)
|
||||||
+227
@@ -0,0 +1,227 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
# KIND, either express or implied. See the License for the
|
||||||
|
# specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Maven2 Start Up Batch script
|
||||||
|
#
|
||||||
|
# Required ENV vars:
|
||||||
|
# ------------------
|
||||||
|
# JAVA_HOME - location of a JDK home dir
|
||||||
|
#
|
||||||
|
# Optional ENV vars
|
||||||
|
# -----------------
|
||||||
|
# M2_HOME - location of maven2's installed home dir
|
||||||
|
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
|
# e.g. to debug Maven itself, use
|
||||||
|
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
|
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||||
|
|
||||||
|
if [ -f /etc/mavenrc ] ; then
|
||||||
|
. /etc/mavenrc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$HOME/.mavenrc" ] ; then
|
||||||
|
. "$HOME/.mavenrc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
# OS specific support. $var _must_ be set to either true or false.
|
||||||
|
cygwin=false;
|
||||||
|
darwin=false;
|
||||||
|
mingw=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN*) cygwin=true ;;
|
||||||
|
MINGW*) mingw=true;;
|
||||||
|
Darwin*) darwin=true
|
||||||
|
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||||
|
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||||
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
|
if [ -x "/usr/libexec/java_home" ]; then
|
||||||
|
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||||
|
else
|
||||||
|
export JAVA_HOME="/Library/Java/Home"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
|
if [ -r /etc/gentoo-release ] ; then
|
||||||
|
JAVA_HOME=`java-config --jre-home`
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$M2_HOME" ] ; then
|
||||||
|
## resolve links - $0 may be a link to maven's home
|
||||||
|
PRG="$0"
|
||||||
|
|
||||||
|
# need this for relative symlinks
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG="`dirname "$PRG"`/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
saveddir=`pwd`
|
||||||
|
|
||||||
|
M2_HOME=`dirname "$PRG"`/..
|
||||||
|
|
||||||
|
# make it fully qualified
|
||||||
|
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||||
|
|
||||||
|
cd "$saveddir"
|
||||||
|
# echo Using m2 at $M2_HOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||||
|
if $cygwin ; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||||
|
[ -n "$CLASSPATH" ] &&
|
||||||
|
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||||
|
if $mingw ; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||||
|
# TODO classpath?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
|
javaExecutable="`which javac`"
|
||||||
|
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||||
|
# readlink(1) is not available as standard on Solaris 10.
|
||||||
|
readLink=`which readlink`
|
||||||
|
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||||
|
if $darwin ; then
|
||||||
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
|
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||||
|
else
|
||||||
|
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||||
|
fi
|
||||||
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
|
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||||
|
JAVA_HOME="$javaHome"
|
||||||
|
export JAVA_HOME
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVACMD" ] ; then
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="`which java`"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||||
|
echo " We cannot execute $JAVACMD" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
|
echo "Warning: JAVA_HOME environment variable is not set."
|
||||||
|
fi
|
||||||
|
|
||||||
|
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||||
|
|
||||||
|
# traverses directory structure from process work directory to filesystem root
|
||||||
|
# first directory with .mvn subdirectory is considered project base directory
|
||||||
|
find_maven_basedir() {
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
echo "Path not specified to find_maven_basedir"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
basedir="$1"
|
||||||
|
wdir="$1"
|
||||||
|
while [ "$wdir" != '/' ] ; do
|
||||||
|
if [ -d "$wdir"/.mvn ] ; then
|
||||||
|
basedir=$wdir
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||||
|
if [ -d "${wdir}" ]; then
|
||||||
|
wdir=`cd "$wdir/.."; pwd`
|
||||||
|
fi
|
||||||
|
# end of workaround
|
||||||
|
done
|
||||||
|
echo "${basedir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# concatenates all lines of a file
|
||||||
|
concat_lines() {
|
||||||
|
if [ -f "$1" ]; then
|
||||||
|
echo "$(tr -s '\n' ' ' < "$1")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||||
|
if [ -z "$BASE_DIR" ]; then
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo $MAVEN_PROJECTBASEDIR
|
||||||
|
fi
|
||||||
|
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||||
|
[ -n "$CLASSPATH" ] &&
|
||||||
|
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||||
|
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||||
|
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
|
exec "$JAVACMD" \
|
||||||
|
$MAVEN_OPTS \
|
||||||
|
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||||
|
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||||
|
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||||
+145
@@ -0,0 +1,145 @@
|
|||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@REM or more contributor license agreements. See the NOTICE file
|
||||||
|
@REM distributed with this work for additional information
|
||||||
|
@REM regarding copyright ownership. The ASF licenses this file
|
||||||
|
@REM to you under the Apache License, Version 2.0 (the
|
||||||
|
@REM "License"); you may not use this file except in compliance
|
||||||
|
@REM with the License. You may obtain a copy of the License at
|
||||||
|
@REM
|
||||||
|
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@REM
|
||||||
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
|
@REM software distributed under the License is distributed on an
|
||||||
|
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@REM KIND, either express or implied. See the License for the
|
||||||
|
@REM specific language governing permissions and limitations
|
||||||
|
@REM under the License.
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Maven2 Start Up Batch script
|
||||||
|
@REM
|
||||||
|
@REM Required ENV vars:
|
||||||
|
@REM JAVA_HOME - location of a JDK home dir
|
||||||
|
@REM
|
||||||
|
@REM Optional ENV vars
|
||||||
|
@REM M2_HOME - location of maven2's installed home dir
|
||||||
|
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||||
|
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
||||||
|
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
|
@REM e.g. to debug Maven itself, use
|
||||||
|
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
|
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||||
|
@echo off
|
||||||
|
@REM set title of command window
|
||||||
|
title %0
|
||||||
|
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
|
||||||
|
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||||
|
|
||||||
|
@REM set %HOME% to equivalent of $HOME
|
||||||
|
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||||
|
|
||||||
|
@REM Execute a user defined script before this one
|
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||||
|
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||||
|
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||||
|
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||||
|
:skipRcPre
|
||||||
|
|
||||||
|
@setlocal
|
||||||
|
|
||||||
|
set ERROR_CODE=0
|
||||||
|
|
||||||
|
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||||
|
@setlocal
|
||||||
|
|
||||||
|
@REM ==== START VALIDATION ====
|
||||||
|
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Error: JAVA_HOME not found in your environment. >&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||||
|
echo location of your Java installation. >&2
|
||||||
|
echo.
|
||||||
|
goto error
|
||||||
|
|
||||||
|
:OkJHome
|
||||||
|
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||||
|
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||||
|
echo location of your Java installation. >&2
|
||||||
|
echo.
|
||||||
|
goto error
|
||||||
|
|
||||||
|
@REM ==== END VALIDATION ====
|
||||||
|
|
||||||
|
:init
|
||||||
|
|
||||||
|
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||||
|
@REM Fallback to current working directory if not found.
|
||||||
|
|
||||||
|
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||||
|
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||||
|
|
||||||
|
set EXEC_DIR=%CD%
|
||||||
|
set WDIR=%EXEC_DIR%
|
||||||
|
:findBaseDir
|
||||||
|
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||||
|
cd ..
|
||||||
|
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||||
|
set WDIR=%CD%
|
||||||
|
goto findBaseDir
|
||||||
|
|
||||||
|
:baseDirFound
|
||||||
|
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||||
|
cd "%EXEC_DIR%"
|
||||||
|
goto endDetectBaseDir
|
||||||
|
|
||||||
|
:baseDirNotFound
|
||||||
|
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||||
|
cd "%EXEC_DIR%"
|
||||||
|
|
||||||
|
:endDetectBaseDir
|
||||||
|
|
||||||
|
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||||
|
|
||||||
|
@setlocal EnableExtensions EnableDelayedExpansion
|
||||||
|
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||||
|
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||||
|
|
||||||
|
:endReadAdditionalConfig
|
||||||
|
|
||||||
|
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||||
|
|
||||||
|
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||||
|
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
|
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||||
|
if ERRORLEVEL 1 goto error
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:error
|
||||||
|
set ERROR_CODE=1
|
||||||
|
|
||||||
|
:end
|
||||||
|
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||||
|
|
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||||
|
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||||
|
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||||
|
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||||
|
:skipRcPost
|
||||||
|
|
||||||
|
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||||
|
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||||
|
|
||||||
|
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||||
|
|
||||||
|
exit /B %ERROR_CODE%
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
<?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-boot-testing</artifactId>
|
||||||
|
<name>spring-boot-testing</name>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<description>This is simple boot application for demonstrating testing features.</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring-boot-modules</groupId>
|
||||||
|
<artifactId>spring-boot-modules</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-bom</artifactId>
|
||||||
|
<version>${log4j2.version}</version>
|
||||||
|
<scope>import</scope>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Embedded Redis Server -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>it.ozimov</groupId>
|
||||||
|
<artifactId>embedded-redis</artifactId>
|
||||||
|
<version>${redis.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Spock & Spring -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spockframework</groupId>
|
||||||
|
<artifactId>spock-core</artifactId>
|
||||||
|
<version>${spock.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spockframework</groupId>
|
||||||
|
<artifactId>spock-spring</artifactId>
|
||||||
|
<version>${spock.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>spring-boot-testing</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>pl.project13.maven</groupId>
|
||||||
|
<artifactId>git-commit-id-plugin</artifactId>
|
||||||
|
<version>${git-commit-id-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>get-the-git-infos</id>
|
||||||
|
<goals>
|
||||||
|
<goal>revision</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>initialize</phase>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>validate-the-git-infos</id>
|
||||||
|
<goals>
|
||||||
|
<goal>validateRevision</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>package</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<generateGitPropertiesFile>true</generateGitPropertiesFile>
|
||||||
|
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.gmavenplus</groupId>
|
||||||
|
<artifactId>gmavenplus-plugin</artifactId>
|
||||||
|
<version>${gmavenplus-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>compileTests</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- The main class to start by executing java -jar -->
|
||||||
|
<start-class>com.baeldung.boot.Application</start-class>
|
||||||
|
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
|
||||||
|
<spock.version>1.2-groovy-2.4</spock.version>
|
||||||
|
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||||
|
<redis.version>0.7.2</redis.version>
|
||||||
|
<spring-boot.version>2.5.0</spring-boot.version>
|
||||||
|
<log4j2.version>2.17.1</log4j2.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.boot;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
private static ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
applicationContext = SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package com.baeldung.boot.configurationproperties;
|
||||||
|
|
||||||
|
public class Credentials {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public Credentials(String username, String password) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.boot.configurationproperties;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConfigurationPropertiesBinding
|
||||||
|
public class CustomCredentialsConverter implements Converter<String, Credentials> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Credentials convert(String source) {
|
||||||
|
String[] data = source.split(",");
|
||||||
|
return new Credentials(data[0], data[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package com.baeldung.boot.configurationproperties;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.Email;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "validate")
|
||||||
|
@PropertySource("classpath:property-validation.properties")
|
||||||
|
@Validated
|
||||||
|
public class MailServer {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@NotEmpty
|
||||||
|
private Map<String, @NotBlank String> propertiesMap;
|
||||||
|
|
||||||
|
@Valid
|
||||||
|
private MailConfig mailConfig = new MailConfig();
|
||||||
|
|
||||||
|
public static class MailConfig {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Email
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getPropertiesMap() {
|
||||||
|
return propertiesMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPropertiesMap(Map<String, String> propertiesMap) {
|
||||||
|
this.propertiesMap = propertiesMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MailConfig getMailConfig() {
|
||||||
|
return mailConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMailConfig(MailConfig mailConfig) {
|
||||||
|
this.mailConfig = mailConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package com.baeldung.boot.configurationproperties;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.convert.DataSizeUnit;
|
||||||
|
import org.springframework.boot.convert.DurationUnit;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.util.unit.DataSize;
|
||||||
|
import org.springframework.util.unit.DataUnit;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "server")
|
||||||
|
public class PropertyConversion {
|
||||||
|
|
||||||
|
private DataSize uploadSpeed;
|
||||||
|
|
||||||
|
@DataSizeUnit(DataUnit.GIGABYTES)
|
||||||
|
private DataSize downloadSpeed;
|
||||||
|
|
||||||
|
private Duration backupDay;
|
||||||
|
|
||||||
|
@DurationUnit(ChronoUnit.HOURS)
|
||||||
|
private Duration backupHour;
|
||||||
|
|
||||||
|
private Credentials credentials;
|
||||||
|
|
||||||
|
public Duration getBackupDay() {
|
||||||
|
return backupDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackupDay(Duration backupDay) {
|
||||||
|
this.backupDay = backupDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Duration getBackupHour() {
|
||||||
|
return backupHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackupHour(Duration backupHour) {
|
||||||
|
this.backupHour = backupHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataSize getUploadSpeed() {
|
||||||
|
return uploadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadSpeed(DataSize uploadSpeed) {
|
||||||
|
this.uploadSpeed = uploadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataSize getDownloadSpeed() {
|
||||||
|
return downloadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadSpeed(DataSize downloadSpeed) {
|
||||||
|
this.downloadSpeed = downloadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Credentials getCredentials() {
|
||||||
|
return credentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCredentials(Credentials credentials) {
|
||||||
|
this.credentials = credentials;
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package com.baeldung.boot.configurationproperties;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "server")
|
||||||
|
public class ServerConfig {
|
||||||
|
|
||||||
|
private Address address;
|
||||||
|
private Map<String, String> resourcesPath;
|
||||||
|
|
||||||
|
public static class Address {
|
||||||
|
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIp(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(Address address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getResourcesPath() {
|
||||||
|
return resourcesPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourcesPath(Map<String, String> resourcesPath) {
|
||||||
|
this.resourcesPath = resourcesPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.baeldung.boot.configurationproperties;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ServerConfigFactory {
|
||||||
|
|
||||||
|
@Bean(name = "default_bean")
|
||||||
|
@ConfigurationProperties(prefix = "server.default")
|
||||||
|
public ServerConfig getDefaultConfigs() {
|
||||||
|
return new ServerConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.boot.controller.rest;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class HomeController {
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public String salutation() {
|
||||||
|
return "Welcome !";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.boot.controller.rest;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/hello")
|
||||||
|
public class WebController {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public String salutation() {
|
||||||
|
return "Hello " + Optional.ofNullable(name).orElse("world") + '!';
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
|
public void setName(@RequestBody final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping
|
||||||
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
|
public void resetToDefault() {
|
||||||
|
this.name = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.boot.embeddedRedis.configuration;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableRedisRepositories
|
||||||
|
public class RedisConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LettuceConnectionFactory redisConnectionFactory(final RedisProperties redisProperties) {
|
||||||
|
return new LettuceConnectionFactory(redisProperties.getRedisHost(), redisProperties.getRedisPort());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<?, ?> redisTemplate(final LettuceConnectionFactory connectionFactory) {
|
||||||
|
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
|
||||||
|
template.setConnectionFactory(connectionFactory);
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.boot.embeddedRedis.configuration;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedisProperties {
|
||||||
|
private final int redisPort;
|
||||||
|
private final String redisHost;
|
||||||
|
|
||||||
|
public RedisProperties(@Value("${spring.redis.port}") final int redisPort, @Value("${spring.redis.host}") final String redisHost) {
|
||||||
|
this.redisPort = redisPort;
|
||||||
|
this.redisHost = redisHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRedisPort() {
|
||||||
|
return redisPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRedisHost() {
|
||||||
|
return redisHost;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.boot.embeddedRedis.domain;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.redis.core.RedisHash;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RedisHash("user")
|
||||||
|
public class User {
|
||||||
|
@Id private UUID id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public User(UUID id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package com.baeldung.boot.embeddedRedis.domain.repository;
|
||||||
|
|
||||||
|
import com.baeldung.boot.embeddedRedis.domain.User;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface UserRepository extends CrudRepository<User, UUID> {
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user