commit
440152b0ba
@ -44,18 +44,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<io.jenetics.version>3.7.0</io.jenetics.version>
|
||||
|
@ -49,18 +49,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -54,18 +54,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -74,18 +74,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-collections4.version>4.3</commons-collections4.version>
|
||||
|
@ -34,18 +34,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<guava.version>27.0.1-jre</guava.version>
|
||||
|
@ -49,18 +49,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<tradukisto.version>1.0.1</tradukisto.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
|
@ -44,18 +44,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
|
@ -45,18 +45,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
|
@ -30,7 +30,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
@ -4,9 +4,9 @@
|
||||
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>aws-lambda-examples</artifactId>
|
||||
<artifactId>lambda</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-lambda-examples</name>
|
||||
<name>lambda</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<artifactId>ShippingFunction</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Shipping Tracker Lambda Function</name>
|
||||
<name>ShippingFunction</name>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
@ -45,7 +45,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
@ -105,7 +104,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
@ -134,7 +132,6 @@
|
||||
|
||||
<properties>
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
<source.version>1.8</source.version>
|
||||
<target.version>1.8</target.version>
|
||||
</properties>
|
||||
|
@ -60,7 +60,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
@ -108,7 +107,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
|
@ -189,7 +189,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
@ -249,7 +248,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
@ -397,7 +395,6 @@
|
||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
|
||||
<spring-boot-maven-plugin.version>2.0.3.RELEASE</spring-boot-maven-plugin.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
<source.version>1.8</source.version>
|
||||
<target.version>1.8</target.version>
|
||||
</properties>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung.servicemodule</groupId>
|
||||
<artifactId>servicemodule1</artifactId>
|
||||
<artifactId>servicemodule</artifactId>
|
||||
<version>${servicemodule.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -5,7 +5,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.servicemodule</groupId>
|
||||
<artifactId>servicemodule1</artifactId>
|
||||
<artifactId>servicemodule</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung.servicemodule</groupId>
|
||||
<artifactId>servicemodule2</artifactId>
|
||||
<artifactId>servicemodule</artifactId>
|
||||
<version>${servicemodule.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -5,7 +5,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.servicemodule</groupId>
|
||||
<artifactId>servicemodule2</artifactId>
|
||||
<artifactId>servicemodule</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<parent>
|
||||
|
@ -62,18 +62,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
|
@ -13,3 +13,4 @@ This module contains articles about types in Java
|
||||
- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums)
|
||||
- [Determine if an Object is of Primitive Type](https://www.baeldung.com/java-object-primitive-type)
|
||||
- [Extending Enums in Java](https://www.baeldung.com/java-extending-enums)
|
||||
- [Java Class File Naming Conventions](https://www.baeldung.com/java-class-file-naming)
|
||||
|
@ -14,5 +14,4 @@ This module contains articles about networking in Java
|
||||
- [Handling java.net.ConnectException](https://www.baeldung.com/java-net-connectexception)
|
||||
- [Getting MAC addresses in Java](https://www.baeldung.com/java-mac-address)
|
||||
- [Sending Emails with Attachments in Java](https://www.baeldung.com/java-send-emails-attachments)
|
||||
- [Finding a Free Port in Java](https://www.baeldung.com/java-free-port)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-networking)
|
||||
|
@ -4,5 +4,5 @@ This module contains articles about networking in Java
|
||||
|
||||
### Relevant Articles
|
||||
|
||||
- TODO: add link once live
|
||||
- [Finding a Free Port in Java](https://www.baeldung.com/java-free-port)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-networking-2)
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.datagramchannel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
public class DatagramChannelBuilder {
|
||||
|
||||
public static DatagramChannel openChannel() throws IOException {
|
||||
DatagramChannel datagramChannel = DatagramChannel.open();
|
||||
return datagramChannel;
|
||||
}
|
||||
|
||||
public static DatagramChannel bindChannel(SocketAddress local) throws IOException {
|
||||
return openChannel().bind(local);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.baeldung.datagramchannel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
public class DatagramClient {
|
||||
|
||||
public static DatagramChannel startClient() throws IOException {
|
||||
DatagramChannel client = DatagramChannelBuilder.bindChannel(null);
|
||||
client.configureBlocking(false);
|
||||
return client;
|
||||
}
|
||||
|
||||
public static void sendMessage(DatagramChannel client, String msg, SocketAddress serverAddress) throws IOException {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
|
||||
client.send(buffer, serverAddress);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
DatagramChannel client = startClient();
|
||||
String msg = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
|
||||
|
||||
sendMessage(client, msg, serverAddress);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.baeldung.datagramchannel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
public class DatagramServer {
|
||||
|
||||
public static DatagramChannel startServer() throws IOException {
|
||||
InetSocketAddress address = new InetSocketAddress("localhost", 7001);
|
||||
DatagramChannel server = DatagramChannelBuilder.bindChannel(address);
|
||||
|
||||
System.out.println("Server started at #" + address);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public static String receiveMessage(DatagramChannel server) throws IOException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
SocketAddress remoteAdd = server.receive(buffer);
|
||||
String message = extractMessage(buffer);
|
||||
|
||||
System.out.println("Client at #" + remoteAdd + " sent: " + message);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private static String extractMessage(ByteBuffer buffer) {
|
||||
buffer.flip();
|
||||
|
||||
byte[] bytes = new byte[buffer.remaining()];
|
||||
buffer.get(bytes);
|
||||
|
||||
String msg = new String(bytes);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
DatagramChannel server = startServer();
|
||||
receiveMessage(server);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.baeldung.datagramchannel;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DatagramChannelUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenClientSendsAndServerReceivesUDPPacket_thenCorrect() throws IOException {
|
||||
DatagramChannel server = DatagramServer.startServer();
|
||||
DatagramChannel client = DatagramClient.startClient();
|
||||
|
||||
String msg1 = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
|
||||
String msg2 = "Hi again!, Are you there!";
|
||||
|
||||
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
|
||||
|
||||
DatagramClient.sendMessage(client, msg1, serverAddress);
|
||||
DatagramClient.sendMessage(client, msg2, serverAddress);
|
||||
|
||||
assertEquals("Hello, this is a Baeldung's DatagramChannel based UDP client!", DatagramServer.receiveMessage(server));
|
||||
assertEquals("Hi again!, Are you there!", DatagramServer.receiveMessage(server));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.baeldung.cipher;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
||||
public class RsaUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenRsaKeyPair_whenEncryptAndDecryptString_thenCompareResults() throws Exception {
|
||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(2048);
|
||||
KeyPair pair = generator.generateKeyPair();
|
||||
PrivateKey privateKey = pair.getPrivate();
|
||||
PublicKey publicKey = pair.getPublic();
|
||||
|
||||
String secretMessage = "Baeldung secret message";
|
||||
Cipher encryptCipher = Cipher.getInstance("RSA");
|
||||
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes);
|
||||
|
||||
Cipher decryptCipher = Cipher.getInstance("RSA");
|
||||
decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes);
|
||||
String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8);
|
||||
|
||||
Assertions.assertEquals(secretMessage, decryptedMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRsaKeyPair_whenEncryptAndDecryptFile_thenCompareResults() throws Exception {
|
||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(2048);
|
||||
KeyPair pair = generator.generateKeyPair();
|
||||
PrivateKey privateKey = pair.getPrivate();
|
||||
PublicKey publicKey = pair.getPublic();
|
||||
|
||||
String originalContent = "some secret message";
|
||||
Path tempFile = Files.createTempFile("temp", "txt");
|
||||
writeString(tempFile, originalContent);
|
||||
|
||||
byte[] fileBytes = Files.readAllBytes(tempFile);
|
||||
Cipher encryptCipher = Cipher.getInstance("RSA");
|
||||
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes);
|
||||
try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) {
|
||||
stream.write(encryptedFileBytes);
|
||||
}
|
||||
|
||||
encryptedFileBytes = Files.readAllBytes(tempFile);
|
||||
Cipher decryptCipher = Cipher.getInstance("RSA");
|
||||
decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes);
|
||||
try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) {
|
||||
stream.write(decryptedFileBytes);
|
||||
}
|
||||
|
||||
String fileContent = readString(tempFile);
|
||||
|
||||
Assertions.assertEquals(originalContent, fileContent);
|
||||
}
|
||||
|
||||
private void writeString(Path path, String content) throws Exception {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
|
||||
writer.write(content);
|
||||
}
|
||||
}
|
||||
|
||||
private String readString(Path path) throws Exception {
|
||||
StringBuilder resultStringBuilder = new StringBuilder();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
resultStringBuilder.append(line);
|
||||
}
|
||||
}
|
||||
return resultStringBuilder.toString();
|
||||
}
|
||||
}
|
@ -10,4 +10,5 @@ This module contains articles about the Stream API in Java.
|
||||
- [Debugging Java 8 Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams)
|
||||
- [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals)
|
||||
- [Should We Close a Java Stream?](https://www.baeldung.com/java-stream-close)
|
||||
- [Returning Stream vs. Collection](https://www.baeldung.com/java-return-stream-collection)
|
||||
- More articles: [[<-- prev>]](/../core-java-streams-2)
|
||||
|
@ -44,7 +44,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
@ -68,7 +67,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
|
@ -94,7 +94,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
@ -154,7 +153,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>run-benchmarks</id>
|
||||
@ -193,7 +191,6 @@
|
||||
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
||||
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
<source.version>1.8</source.version>
|
||||
<target.version>1.8</target.version>
|
||||
</properties>
|
||||
|
@ -100,6 +100,7 @@
|
||||
|
||||
<module>core-java-networking</module>
|
||||
<module>core-java-networking-2</module>
|
||||
<module>core-java-networking-3</module>
|
||||
<module>core-java-nio</module>
|
||||
<module>core-java-nio-2</module>
|
||||
|
||||
|
@ -35,7 +35,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
@ -2,21 +2,18 @@
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.5.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>discord4j-bot</artifactId>
|
||||
<artifactId>discord4j</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>discord4j-bot</name>
|
||||
<name>discord4j</name>
|
||||
<description>Demo Discord bot using Discord4J + Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -67,5 +64,9 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -2,21 +2,18 @@
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.baeldung.docker</groupId>
|
||||
<artifactId>docker-spring-boot-postgres</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>docker-spring-boot-postgres</name>
|
||||
<description>Demo project showing Spring Boot, PostgreSQL, and Docker</description>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -44,5 +41,9 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -4,19 +4,19 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.1.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.baeldung.docker</groupId>
|
||||
<artifactId>docker</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<name>docker</name>
|
||||
<description>Demo project showing Spring Boot and Docker</description>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<artifactId>bookstore-monolith</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>Bookstore</name>
|
||||
<name>bookstore-monolith</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>jhipster-5</artifactId>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<groupId>com.baeldung.jhipster.gateway</groupId>
|
||||
<artifactId>gateway</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Gateway</name>
|
||||
<name>gateway</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<repositories>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<groupId>com.baeldung.jhipster.quotes</groupId>
|
||||
<artifactId>quotes</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Quotes</name>
|
||||
<name>quotes</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<repositories>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<groupId>com.baeldung.jhipster.uaa</groupId>
|
||||
<artifactId>uaa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Uaa</name>
|
||||
<name>uaa</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<repositories>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>kubernetes-parent</artifactId>
|
||||
<artifactId>kubernetes</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>k8s-intro</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>kubernetes-parent</artifactId>
|
||||
<artifactId>kubernetes</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>k8s-intro</module>
|
||||
|
@ -189,7 +189,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-server</id>
|
||||
@ -229,7 +228,6 @@
|
||||
<httpcore.version>4.4.13</httpcore.version>
|
||||
<httpclient.version>4.5.12</httpclient.version>
|
||||
<velocity-engine-core.version>2.2</velocity-engine-core.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
<nullaway.version>0.3.0</nullaway.version>
|
||||
<plexus-compiler.version>2.8</plexus-compiler.version>
|
||||
<errorprone.version>2.1.3</errorprone.version>
|
||||
|
@ -47,7 +47,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.quasar.App</mainClass>
|
||||
<workingDirectory>target/classes</workingDirectory>
|
||||
|
@ -14,11 +14,11 @@
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>flogger</module>
|
||||
<module>log4j</module>
|
||||
<module>log4j2</module>
|
||||
<module>logback</module>
|
||||
<module>log-mdc</module>
|
||||
<module>flogger</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
@ -20,14 +20,15 @@
|
||||
<module>maven-integration-test</module>
|
||||
<module>maven-multi-source</module>
|
||||
<module>maven-plugins</module>
|
||||
<module>maven-unused-dependencies</module>
|
||||
<module>maven-war-plugin</module>
|
||||
<module>maven-profiles</module>
|
||||
<module>maven-properties</module>
|
||||
<module>versions-maven-plugin</module>
|
||||
<module>version-collision</module>
|
||||
<!-- <module>maven-proxy</module> --> <!-- Not a maven project -->
|
||||
<module>maven-unused-dependencies</module>
|
||||
<module>maven-war-plugin</module>
|
||||
<module>optional-dependencies</module>
|
||||
<module>version-collision</module>
|
||||
<module>version-overriding-plugins</module>
|
||||
<module>versions-maven-plugin</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
@ -102,7 +102,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec.plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<arguments>
|
||||
@ -146,7 +145,6 @@
|
||||
<lombok.version>1.2.3</lombok.version>
|
||||
<reactor.version>3.1.6.RELEASE</reactor.version>
|
||||
<compiler.plugin.version>3.7.0</compiler.plugin.version>
|
||||
<exec.plugin.version>1.6.0</exec.plugin.version>
|
||||
<shade.plugin.version>3.1.0</shade.plugin.version>
|
||||
</properties>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
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>genie</artifactId>
|
||||
<name>Genie</name>
|
||||
<name>genie</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Sample project for Netflix Genie</description>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
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>mantis</artifactId>
|
||||
<name>Mantis</name>
|
||||
<name>mantis</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Sample project for Netflix Mantis</description>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
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>netflix-modules</artifactId>
|
||||
<name>Netflix Modules</name>
|
||||
<name>netflix-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
<description>Module for Netflix projects</description>
|
||||
|
||||
|
@ -2,3 +2,4 @@
|
||||
|
||||
- [Getting Database URL From JDBC Connection Object](https://www.baeldung.com/jdbc-get-url-from-connection)
|
||||
- [JDBC URL Format For Different Databases](https://www.baeldung.com/java-jdbc-url-format)
|
||||
- [How to Check if a Database Table Exists with JDBC](https://www.baeldung.com/jdbc-check-table-exists)
|
||||
|
@ -0,0 +1,103 @@
|
||||
package com.baeldung.hibernate.lazycollection.model;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Entity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class Branch {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Branch() {
|
||||
}
|
||||
public Branch(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "mainBranch")
|
||||
@LazyCollection(LazyCollectionOption.TRUE)
|
||||
private List<Employee> mainEmployees;
|
||||
|
||||
@OneToMany(mappedBy = "subBranch")
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
private List<Employee> subEmployees;
|
||||
|
||||
@OneToMany(mappedBy = "additionalBranch")
|
||||
@LazyCollection(LazyCollectionOption.EXTRA)
|
||||
@OrderColumn(name = "order_id")
|
||||
private List<Employee> additionalEmployees;
|
||||
|
||||
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 List<Employee> getMainEmployees() {
|
||||
return mainEmployees;
|
||||
}
|
||||
|
||||
public void setMainEmployees(List<Employee> mainEmployees) {
|
||||
this.mainEmployees = mainEmployees;
|
||||
}
|
||||
|
||||
public List<Employee> getSubEmployees() {
|
||||
return subEmployees;
|
||||
}
|
||||
|
||||
public void setSubEmployees(List<Employee> subEmployees) {
|
||||
this.subEmployees = subEmployees;
|
||||
}
|
||||
|
||||
public List<Employee> getAdditionalEmployees() {
|
||||
return additionalEmployees;
|
||||
}
|
||||
|
||||
public void setAdditionalEmployees(List<Employee> additionalEmployees) {
|
||||
this.additionalEmployees = additionalEmployees;
|
||||
}
|
||||
|
||||
public void addMainEmployee(Employee employee) {
|
||||
if (this.mainEmployees == null) {
|
||||
this.mainEmployees = new ArrayList<>();
|
||||
}
|
||||
this.mainEmployees.add(employee);
|
||||
}
|
||||
|
||||
public void addSubEmployee(Employee employee) {
|
||||
if (this.subEmployees == null) {
|
||||
this.subEmployees = new ArrayList<>();
|
||||
}
|
||||
this.subEmployees.add(employee);
|
||||
}
|
||||
|
||||
public void addAdditionalEmployee(Employee employee) {
|
||||
if (this.additionalEmployees == null) {
|
||||
this.additionalEmployees = new ArrayList<>();
|
||||
}
|
||||
this.additionalEmployees.add(employee);
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.baeldung.hibernate.lazycollection.model;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class Employee {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String address;
|
||||
|
||||
public Employee() {
|
||||
|
||||
}
|
||||
|
||||
public Employee(String name, Branch mainBranch, Branch subBranch, Branch additionalBranch) {
|
||||
this.name = name;
|
||||
this.mainBranch = mainBranch;
|
||||
this.subBranch = subBranch;
|
||||
this.additionalBranch = additionalBranch;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
private Branch mainBranch;
|
||||
|
||||
@ManyToOne
|
||||
private Branch subBranch;
|
||||
|
||||
@ManyToOne
|
||||
private Branch additionalBranch;
|
||||
|
||||
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 getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Branch getMainBranch() {
|
||||
return mainBranch;
|
||||
}
|
||||
|
||||
public void setMainBranch(Branch mainBranch) {
|
||||
this.mainBranch = mainBranch;
|
||||
}
|
||||
|
||||
public Branch getSubBranch() {
|
||||
return subBranch;
|
||||
}
|
||||
|
||||
public void setSubBranch(Branch subBranch) {
|
||||
this.subBranch = subBranch;
|
||||
}
|
||||
|
||||
public Branch getAdditionalBranch() {
|
||||
return additionalBranch;
|
||||
}
|
||||
|
||||
public void setAdditionalBranch(Branch additionalBranch) {
|
||||
this.additionalBranch = additionalBranch;
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.baeldung.hibernate.lazycollection;
|
||||
|
||||
import com.baeldung.hibernate.lazycollection.model.Branch;
|
||||
import com.baeldung.hibernate.lazycollection.model.Employee;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
public class LazyCollectionIntegrationTest {
|
||||
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
private Session session;
|
||||
|
||||
Branch branch;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeTests() {
|
||||
Configuration configuration = new Configuration().addAnnotatedClass(Branch.class)
|
||||
.addAnnotatedClass(Employee.class).setProperty("hibernate.dialect", H2Dialect.class.getName())
|
||||
.setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName())
|
||||
.setProperty("hibernate.connection.url", "jdbc:h2:mem:test")
|
||||
.setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "")
|
||||
.setProperty("hibernate.hbm2ddl.auto", "update");
|
||||
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.getProperties()).build();
|
||||
|
||||
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
branch = new Branch("Main Branch");
|
||||
|
||||
session.save(branch);
|
||||
|
||||
Employee mainEmployee1 = new Employee("main employee 1", branch, null, null);
|
||||
Employee mainEmployee2 = new Employee("main employee 2", branch, null, null);
|
||||
Employee mainEmployee3 = new Employee("main employee 3", branch, null, null);
|
||||
|
||||
session.save(mainEmployee1);
|
||||
session.save(mainEmployee2);
|
||||
session.save(mainEmployee3);
|
||||
|
||||
Employee subEmployee1 = new Employee("sub employee 1", null, branch, null);
|
||||
Employee subEmployee2 = new Employee("sub employee 2", null, branch, null);
|
||||
Employee subEmployee3 = new Employee("sub employee 3", null, branch, null);
|
||||
|
||||
session.save(subEmployee1);
|
||||
session.save(subEmployee2);
|
||||
session.save(subEmployee3);
|
||||
|
||||
Employee additionalEmployee1 = new Employee("additional employee 1", null, null, branch);
|
||||
Employee additionalEmployee2 = new Employee("additional employee 2", null, null, branch);
|
||||
Employee additionalEmployee3 = new Employee("additional employee 3", null, null, branch);
|
||||
|
||||
session.save(additionalEmployee1);
|
||||
session.save(additionalEmployee2);
|
||||
session.save(additionalEmployee3);
|
||||
|
||||
session.flush();
|
||||
session.refresh(branch);
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyFetching() {
|
||||
Assert.assertFalse(Hibernate.isInitialized(branch.getMainEmployees()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEagerFetching() {
|
||||
Assert.assertTrue(Hibernate.isInitialized(branch.getSubEmployees()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtraFetching() {
|
||||
Assert.assertFalse(Hibernate.isInitialized(branch.getAdditionalEmployees()));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterTests() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
public class HibernateConfig {
|
||||
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
@ -16,12 +17,12 @@ public class HibernateConfig {
|
||||
Configuration configuration = new Configuration();
|
||||
|
||||
Properties settings = new Properties();
|
||||
settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
|
||||
settings.put(Environment.URL, "jdbc:mysql://localhost:3306/app_db?useSSL=false");
|
||||
settings.put(Environment.USER, "root");
|
||||
settings.put(Environment.PASS, "password");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
|
||||
settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
|
||||
settings.put(Environment.DRIVER, "org.h2.Driver");
|
||||
settings.put(Environment.URL, "jdbc:h2:mem:test");
|
||||
settings.put(Environment.USER, "sa");
|
||||
settings.put(Environment.PASS, "");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
|
||||
settings.put(Environment.HBM2DDL_AUTO, "create-drop");
|
||||
configuration.setProperties(settings);
|
||||
|
||||
configuration.addAnnotatedClass(User.class);
|
||||
|
@ -1,18 +1,24 @@
|
||||
package com.baeldung.ignorable.fields;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TransientFieldUnitTest {
|
||||
|
||||
@ -34,18 +40,20 @@ public class TransientFieldUnitTest {
|
||||
@Test
|
||||
public void givenFieldWithTransientAnnotation_whenSerializingObject_thenFieldSerialized() throws IOException, ClassNotFoundException {
|
||||
|
||||
FileOutputStream fout = new FileOutputStream("test.obj");
|
||||
ObjectOutputStream out = new ObjectOutputStream(fout);
|
||||
out.writeObject(user);
|
||||
out.flush();
|
||||
out.close();
|
||||
try (FileOutputStream fout = new FileOutputStream("test.obj")) {
|
||||
ObjectOutputStream out = new ObjectOutputStream(fout);
|
||||
out.writeObject(user);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
FileInputStream fin = new FileInputStream("test.obj");
|
||||
ObjectInputStream in = new ObjectInputStream(fin);
|
||||
User savedUser = (User) in.readObject();
|
||||
in.close();
|
||||
try (FileInputStream fin = new FileInputStream("test.obj")) {
|
||||
ObjectInputStream in = new ObjectInputStream(fin);
|
||||
User savedUser = (User) in.readObject();
|
||||
|
||||
assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice());
|
||||
assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice());
|
||||
}
|
||||
|
||||
Files.deleteIfExists(Paths.get("test.obj"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -55,7 +55,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>document</id>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>jooq-examples</name>
|
||||
<name>jooq</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>jOOQ Examples</description>
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
<module>java-jdbi</module>
|
||||
<module>java-jpa</module> <!-- long running -->
|
||||
<module>java-jpa-2</module> <!-- long running -->
|
||||
<module>java-jpa-3</module>
|
||||
<module>java-mongodb</module> <!-- long running -->
|
||||
<module>jnosql</module> <!-- long running -->
|
||||
<module>jooq</module>
|
||||
|
@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
<name>spring-data-cosmos-db</name>
|
||||
<name>spring-data-cosmosdb</name>
|
||||
<description>tutorial for spring-data-cosmosdb</description>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
@ -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="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
@ -6,18 +6,15 @@ import com.baeldung.projection.repository.PersonRepository;
|
||||
import com.baeldung.projection.view.AddressView;
|
||||
import com.baeldung.projection.view.PersonDto;
|
||||
import com.baeldung.projection.view.PersonView;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
|
||||
|
||||
@DataJpaTest
|
||||
@RunWith(SpringRunner.class)
|
||||
@Sql(scripts = "/projection-insert-data.sql")
|
||||
@Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public class JpaProjectionIntegrationTest {
|
||||
|
@ -5,6 +5,7 @@ This module contains articles about Spring with jOOQ
|
||||
### Relevant Articles:
|
||||
- [Spring Boot Support for jOOQ](https://www.baeldung.com/spring-boot-support-for-jooq)
|
||||
- [Introduction to jOOQ with Spring](https://www.baeldung.com/jooq-with-spring)
|
||||
- [Count Query In jOOQ](https://www.baeldung.com/jooq-count-query)
|
||||
|
||||
In order to fix the error "Plugin execution not covered by lifecycle configuration: org.jooq:jooq-codegen-maven:3.7.3:generate (execution: default, phase: generate-sources)", right-click on the error message and choose "Mark goal generated as ignore in pom.xml". Until version 1.4.x, the maven-plugin-plugin was covered by the default lifecycle mapping that ships with m2e.
|
||||
|
||||
|
17
pom.xml
17
pom.xml
@ -412,6 +412,7 @@
|
||||
<module>google-web-toolkit</module>
|
||||
<!-- <module>gradle</module> --> <!-- Not a maven project -->
|
||||
<!-- <module>gradle-5</module> --> <!-- Not a maven project -->
|
||||
<!-- <module>gradle-6</module> --> <!-- Not a maven project -->
|
||||
<!-- <module>grails</module> --> <!-- Not a maven project -->
|
||||
<module>graphql/graphql-java</module>
|
||||
<module>grpc</module>
|
||||
@ -614,11 +615,12 @@
|
||||
<module>spring-aop</module>
|
||||
<module>spring-apache-camel</module>
|
||||
|
||||
<module>spring-batch</module>
|
||||
<module>spring-batch-2</module>
|
||||
<module>spring-batch</module>
|
||||
<module>spring-batch-2</module>
|
||||
<module>spring-bom</module>
|
||||
<module>spring-boot-modules</module>
|
||||
<module>spring-boot-rest</module>
|
||||
<module>spring-boot-rest-2</module>
|
||||
|
||||
<module>spring-caching</module>
|
||||
|
||||
@ -875,6 +877,7 @@
|
||||
<module>google-web-toolkit</module>
|
||||
<!-- <module>gradle</module> --> <!-- Not a maven project -->
|
||||
<!-- <module>gradle-5</module> --> <!-- Not a maven project -->
|
||||
<!-- <module>gradle-6</module> --> <!-- Not a maven project -->
|
||||
<!-- <module>grails</module> --> <!-- Not a maven project -->
|
||||
<module>graphql/graphql-java</module>
|
||||
<module>grpc</module>
|
||||
@ -930,6 +933,7 @@
|
||||
<module>jooby</module>
|
||||
<module>jsf</module>
|
||||
<module>json</module>
|
||||
<module>json-2</module>
|
||||
<module>json-path</module>
|
||||
<module>jsoup</module>
|
||||
<module>jta</module>
|
||||
@ -1068,9 +1072,11 @@
|
||||
<module>spring-apache-camel</module>
|
||||
|
||||
<module>spring-batch</module>
|
||||
<module>spring-batch-2</module>
|
||||
<module>spring-bom</module>
|
||||
<module>spring-boot-modules</module>
|
||||
<module>spring-boot-rest</module>
|
||||
<module>spring-boot-rest-2</module>
|
||||
|
||||
<module>spring-caching</module>
|
||||
|
||||
@ -1089,6 +1095,7 @@
|
||||
<module>spring-data-rest</module>
|
||||
<module>spring-data-rest-querydsl</module>
|
||||
<module>spring-di</module>
|
||||
<module>spring-di-2</module>
|
||||
<module>spring-drools</module>
|
||||
|
||||
<module>spring-ejb</module>
|
||||
@ -1273,7 +1280,7 @@
|
||||
<!-- <module>core-java-modules/core-java-9-new-features</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
<module>core-java-modules/core-java-9-streams</module>
|
||||
<module>core-java-modules/core-java-10</module>
|
||||
<module>core-java-modules/core-java-11</module>
|
||||
<module>core-java-modules/core-java-11-2</module>
|
||||
<!-- <module>core-java-modules/core-java-12</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
<!-- <module>core-java-modules/core-java-13</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
<!-- <module>core-java-modules/core-java-14</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
@ -1318,6 +1325,7 @@
|
||||
<module>core-java-modules/core-java-9-streams</module>
|
||||
<module>core-java-modules/core-java-10</module>
|
||||
<module>core-java-modules/core-java-11</module>
|
||||
<module>core-java-modules/core-java-11-2</module>
|
||||
<!-- <module>core-java-modules/core-java-12</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
<!-- <module>core-java-modules/core-java-13</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
<!-- <module>core-java-modules/core-java-14</module> --> <!-- uses preview features, to be decided how to handle -->
|
||||
@ -1367,13 +1375,12 @@
|
||||
<!-- can't upgrade the plugin yet; as there is an issue with 2.22 no longer running all the tests-->
|
||||
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
|
||||
<java.version>1.8</java.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<esapi.version>2.2.2.0</esapi.version>
|
||||
<jmh-core.version>1.28</jmh-core.version>
|
||||
<jmh-generator.version>1.28</jmh-generator.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
||||
<commons-io.version>2.8.0</commons-io.version>
|
||||
<commons-lang.version>2.6</commons-lang.version>
|
||||
|
@ -40,7 +40,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<executable>java</executable>
|
||||
<mainClass>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</mainClass>
|
||||
|
@ -45,7 +45,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.examples.slack.MainClass</mainClass>
|
||||
</configuration>
|
||||
|
@ -9,4 +9,5 @@ This module contains articles about reactive Spring 5
|
||||
- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams)
|
||||
- [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content)
|
||||
- [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events)
|
||||
- [Backpressure Mechanism in Spring WebFlux](https://www.baeldung.com/spring-webflux-backpressure)
|
||||
- More articles: [[<-- prev]](/spring-5-reactive)
|
||||
|
@ -0,0 +1,82 @@
|
||||
package com.baeldung.backpressure;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.BaseSubscriber;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
public class BackpressureUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenLimitRateSet_thenSplitIntoChunks() throws InterruptedException {
|
||||
Flux<Integer> limit = Flux.range(1, 25);
|
||||
|
||||
limit.limitRate(10);
|
||||
limit.subscribe(
|
||||
value -> System.out.println(value),
|
||||
err -> err.printStackTrace(),
|
||||
() -> System.out.println("Finished!!"),
|
||||
subscription -> subscription.request(15)
|
||||
);
|
||||
|
||||
StepVerifier.create(limit)
|
||||
.expectSubscription()
|
||||
.thenRequest(15)
|
||||
.expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||
.expectNext(11, 12, 13, 14, 15)
|
||||
.thenRequest(10)
|
||||
.expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestingChunks10_thenMessagesAreReceived() {
|
||||
Flux<Integer> request = Flux.range(1, 50);
|
||||
|
||||
request.subscribe(
|
||||
System.out::println,
|
||||
err -> err.printStackTrace(),
|
||||
() -> System.out.println("All 50 items have been successfully processed!!!"),
|
||||
subscription -> {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
System.out.println("Requesting the next 10 elements!!!");
|
||||
subscription.request(10);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
StepVerifier.create(request)
|
||||
.expectSubscription()
|
||||
.thenRequest(10)
|
||||
.expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||
.thenRequest(10)
|
||||
.expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
|
||||
.thenRequest(10)
|
||||
.expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30)
|
||||
.thenRequest(10)
|
||||
.expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40)
|
||||
.thenRequest(10)
|
||||
.expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCancel_thenSubscriptionFinished() {
|
||||
Flux<Integer> cancel = Flux.range(1, 10).log();
|
||||
|
||||
cancel.subscribe(new BaseSubscriber<Integer>() {
|
||||
@Override
|
||||
protected void hookOnNext(Integer value) {
|
||||
request(3);
|
||||
System.out.println(value);
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
|
||||
StepVerifier.create(cancel)
|
||||
.expectNext(1, 2, 3)
|
||||
.thenCancel()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Concurrent Test Execution in Spring 5](https://www.baeldung.com/spring-5-concurrent-tests)
|
@ -10,3 +10,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Liveness and Readiness Probes in Spring Boot](https://www.baeldung.com/spring-liveness-readiness-probes)
|
||||
- [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom)
|
||||
- [Health Indicators in Spring Boot](https://www.baeldung.com/spring-boot-health-indicators)
|
||||
- [How to Enable All Endpoints in Spring Boot Actuator](https://www.baeldung.com/spring-boot-actuator-enable-endpoints)
|
||||
|
@ -17,20 +17,20 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
auth.inMemoryAuthentication()
|
||||
.withUser("user")
|
||||
.password(encoder.encode("password"))
|
||||
.roles("USER")
|
||||
.and()
|
||||
.withUser("admin")
|
||||
.password(encoder.encode("admin"))
|
||||
.roles("USER", "ADMIN");
|
||||
.withUser("user")
|
||||
.password(encoder.encode("password"))
|
||||
.roles("USER")
|
||||
.and()
|
||||
.withUser("admin")
|
||||
.password(encoder.encode("admin"))
|
||||
.roles("USER", "ADMIN");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint())
|
||||
.authorizeRequests((requests) -> requests.anyRequest()
|
||||
.hasRole("ADMIN"));
|
||||
.authorizeRequests((requests) -> requests.anyRequest()
|
||||
.hasRole("ADMIN"));
|
||||
http.httpBasic();
|
||||
}
|
||||
}
|
||||
|
@ -21,16 +21,16 @@ public class EndpointEnablingIntegrationTest {
|
||||
@WithMockUser(username = "user", password = "password", roles = "USER")
|
||||
public void givenWrongAuthentication_whenCallingActuator_thenReturns401() throws Exception {
|
||||
mockMvc.perform(get("/actuator"))
|
||||
.andExpect(status().isForbidden());
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
|
||||
public void givenProperAuthentication_whenCallingActuator_thenReturnsExpectedEndpoints() throws Exception {
|
||||
mockMvc.perform(get("/actuator"))
|
||||
.andExpect(jsonPath("$._links").exists())
|
||||
.andExpect(jsonPath("$._links.beans").exists())
|
||||
.andExpect(jsonPath("$._links.env").exists())
|
||||
.andExpect(jsonPath("$._links.shutdown").exists());
|
||||
.andExpect(jsonPath("$._links").exists())
|
||||
.andExpect(jsonPath("$._links.beans").exists())
|
||||
.andExpect(jsonPath("$._links.env").exists())
|
||||
.andExpect(jsonPath("$._links.shutdown").exists());
|
||||
}
|
||||
}
|
||||
|
@ -5,3 +5,4 @@ This module contains articles about various Spring Boot libraries
|
||||
### Relevant Articles:
|
||||
|
||||
- [Background Jobs in Spring with JobRunr](https://www.baeldung.com/java-jobrunr-spring)
|
||||
- [Open API Server Implementation Using OpenAPI Generator](https://www.baeldung.com/java-openapi-generator-server)
|
||||
|
@ -16,18 +16,20 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
@AutoConfigureMockMvc
|
||||
public class OpenApiPetsIntegrationTest {
|
||||
|
||||
private static final String PETS_PATH = "/pets/";
|
||||
private static final String PETS_PATH = "/pets/";
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
public void whenReadAll_thenStatusIsNotImplemented() throws Exception {
|
||||
this.mockMvc.perform(get(PETS_PATH)).andExpect(status().isNotImplemented());
|
||||
}
|
||||
@Test
|
||||
public void whenReadAll_thenStatusIsNotImplemented() throws Exception {
|
||||
this.mockMvc.perform(get(PETS_PATH))
|
||||
.andExpect(status().isNotImplemented());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadOne_thenStatusIsNotImplemented() throws Exception {
|
||||
this.mockMvc.perform(get(PETS_PATH + 1)).andExpect(status().isNotImplemented());
|
||||
}
|
||||
@Test
|
||||
public void whenReadOne_thenStatusIsNotImplemented() throws Exception {
|
||||
this.mockMvc.perform(get(PETS_PATH + 1))
|
||||
.andExpect(status().isNotImplemented());
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.baeldung.lazyinitialization;
|
||||
import com.baeldung.lazyinitialization.services.Writer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@ -20,7 +21,9 @@ public class Application {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ApplicationContext ctx = SpringApplication.run(Application.class, args);
|
||||
|
||||
System.out.println("Application context initialized!!!");
|
||||
|
||||
Writer writer1 = ctx.getBean("writer1", Writer.class);
|
||||
@ -29,4 +32,23 @@ public class Application {
|
||||
Writer writer2 = ctx.getBean("writer2", Writer.class);
|
||||
writer2.write("Second message");
|
||||
}
|
||||
|
||||
/*
|
||||
This method shows how to set lazy initialization and start the application using SpringApplicationBuilder
|
||||
*/
|
||||
private static ApplicationContext runUsingSpringApplicationBuilder(String[] args){
|
||||
return new SpringApplicationBuilder(Application.class)
|
||||
.lazyInitialization(true)
|
||||
.build(args)
|
||||
.run();
|
||||
}
|
||||
|
||||
/*
|
||||
This method shows how to set lazy initialization and start the application using SpringApplication
|
||||
*/
|
||||
private static ApplicationContext runUsingSpringApplication(String[] args){
|
||||
SpringApplication app = new SpringApplication(Application.class);
|
||||
app.setLazyInitialization(true);
|
||||
return app.run(args);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,6 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.propertyexpansion.SpringBootPropertyExpansionApp</mainClass>
|
||||
</configuration>
|
||||
@ -80,7 +79,6 @@
|
||||
<properties>
|
||||
<custom.property>Custom Property Value</custom.property>
|
||||
<apache-maven.version>2.7</apache-maven.version>
|
||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -34,8 +34,7 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-dependencies.version>Hoxton.SR4</spring-cloud-dependencies.version>
|
||||
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
|
||||
<spring-cloud-dependencies.version>2020.0.0</spring-cloud-dependencies.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -44,6 +44,7 @@
|
||||
<module>spring-cloud-circuit-breaker</module>
|
||||
<module>spring-cloud-eureka-self-preservation</module>
|
||||
<!--<module>spring-cloud-openfeign</module>--> <!-- Fixing in JAVA-2820 -->
|
||||
<module>spring-cloud-sentinel</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
@ -77,7 +78,7 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-dependencies.version>Hoxton.SR4</spring-cloud-dependencies.version>
|
||||
<spring-cloud-dependencies.version>2020.0.1</spring-cloud-dependencies.version>
|
||||
<spring-cloud-starter-config.version>2.2.3.RELEASE</spring-cloud-starter-config.version>
|
||||
<spring-cloud-config-server.version>2.2.3.RELEASE</spring-cloud-config-server.version>
|
||||
<spring-cloud-starter-eureka.version>1.4.7.RELEASE</spring-cloud-starter-eureka.version>
|
||||
|
3
spring-cloud/spring-cloud-docker/README.md
Normal file
3
spring-cloud/spring-cloud-docker/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
## Relevant Articles:
|
||||
|
||||
- [Dockerizing a Spring Boot Application](https://www.baeldung.com/dockerizing-spring-boot-application)
|
@ -1,12 +1,9 @@
|
||||
package com.baeldung.spring.cloud.hystrix.rest.consumer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = RestConsumerFeignApplication.class)
|
||||
@WebAppConfiguration
|
||||
public class SpringContextTest {
|
||||
|
@ -11,7 +11,7 @@
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-hystrix</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.baeldung.spring.cloud.hystrix.rest.consumer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = RestConsumerApplication.class)
|
||||
@WebAppConfiguration
|
||||
public class SpringContextTest {
|
||||
|
@ -1,11 +1,8 @@
|
||||
package com.baeldung.spring.cloud.hystrix.rest.producer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -15,13 +15,6 @@
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
|
||||
@ -57,6 +50,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
||||
<version>2.2.7.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
@ -65,6 +59,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
|
||||
<version>2.2.7.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -89,8 +84,7 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-dependencies.version>Hoxton.SR1</spring-cloud-dependencies.version>
|
||||
<spring.cloud.k8s.version>1.0.0.RELEASE</spring.cloud.k8s.version>
|
||||
<spring.cloud.k8s.version>1.1.8.RELEASE</spring.cloud.k8s.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.spring.cloud.kubernetes.client.Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -14,13 +14,6 @@
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
@ -70,7 +63,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-dependencies.version>Finchley.SR2</spring-cloud-dependencies.version>
|
||||
<logback.version>1.2.3</logback.version>
|
||||
</properties>
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.baeldung.spring.cloud.kubernetes.travelagency;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.spring.cloud.kubernetes.backend.KubernetesBackendApplication;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = KubernetesBackendApplication.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.spring.cloud.kubernetes.frontend.KubernetesFrontendApplication;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = KubernetesFrontendApplication.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.baeldung;
|
||||
|
||||
import com.baeldung.liveness.Application;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.baeldung;
|
||||
|
||||
import com.baeldung.readiness.Application;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -15,6 +15,18 @@
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud-dependencies.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<modules>
|
||||
<module>kubernetes-minikube/demo-frontend</module>
|
||||
<module>kubernetes-minikube/demo-backend</module>
|
||||
@ -25,6 +37,6 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
|
||||
<spring-cloud-dependencies.version>2020.0.1</spring-cloud-dependencies.version>
|
||||
</properties>
|
||||
</project>
|
@ -37,6 +37,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
|
||||
<version>2.2.7.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -45,8 +46,7 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-dependencies.version>Hoxton.SR4</spring-cloud-dependencies.version>
|
||||
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
|
||||
<spring-cloud-dependencies.version>2020.0.1</spring-cloud-dependencies.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,13 +1,10 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.spring.cloud.ribbon.client.ServerLocationApp;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ServerLocationApp.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -13,30 +13,15 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-oauth2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
|
||||
<version>${spring-cloud-starter-netflix-zuul.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -92,7 +77,7 @@
|
||||
|
||||
<properties>
|
||||
<js-cookie.version>2.2.0</js-cookie.version>
|
||||
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
|
||||
<spring-cloud-starter-netflix-zuul.version>2.2.7.RELEASE</spring-cloud-starter-netflix-zuul.version>
|
||||
<jquery.version>3.4.1</jquery.version>
|
||||
<bootstrap.version>4.3.1</bootstrap.version>
|
||||
</properties>
|
||||
|
@ -1,13 +1,8 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.CloudSite;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = CloudSite.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.baeldung.example.springoath2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.CloudSite;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = CloudSite.class)
|
||||
public class Springoath2ApplicationIntegrationTest {
|
||||
|
||||
|
@ -13,18 +13,6 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -56,7 +44,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
|
||||
<spring-jwt.version>1.0.10.RELEASE</spring-jwt.version>
|
||||
</properties>
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
package com.baeldung.service.personservice;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class PersonserviceApplicationIntegrationTest {
|
||||
|
||||
|
@ -31,14 +31,9 @@
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-oauth2</artifactId>
|
||||
<version>${spring-cloud-starter-oauth2.version}</version>
|
||||
<groupId>org.springframework.security.oauth.boot</groupId>
|
||||
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-starter-oauth2.version>2.1.2.RELEASE</spring-cloud-starter-oauth2.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user