Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Philippe 2018-07-28 13:35:03 -03:00
commit bdbba67eb3
108 changed files with 1412 additions and 427 deletions

View File

@ -0,0 +1,3 @@
### Relevant Articles:
================================
- [Building a Microservice with Apache Meecrowave](http://www.baeldung.com/apache-meecrowave)

View File

@ -54,3 +54,5 @@
- [Java 8 Unsigned Arithmetic Support](http://www.baeldung.com/java-unsigned-arithmetic)
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)
- [Generalized Target-Type Inference in Java](http://www.baeldung.com/java-generalized-target-type-inference)
- [Image to Base64 String Conversion](http://www.baeldung.com/java-base64-image-string)
- [Calculate Age in Java](http://www.baeldung.com/java-get-age)

View File

@ -0,0 +1,87 @@
package com.baeldung.list;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
import static org.junit.Assert.*;
public class AddElementsUnitTest {
List<Flower> flowers;
@Before
public void init() {
this.flowers = new ArrayList<>(Arrays.asList(
new Flower("Poppy", 12),
new Flower("Anemone", 8),
new Flower("Catmint", 12)));
}
@Test
public void givenAList_whenTargetListIsEmpty_thenReturnTargetListWithNewItems() {
List<Flower> anotherList = new ArrayList<>();
anotherList.addAll(flowers);
assertEquals(anotherList.size(), flowers.size());
Assert.assertTrue(anotherList.containsAll(flowers));
}
@Test
public void givenAList_whenTargetListIsEmpty_thenReturnTargetListWithOneModifiedElementByConstructor() {
List<Flower> anotherList = new ArrayList<>();
anotherList.addAll(flowers);
Flower flower = anotherList.get(0);
flower.setPetals(flowers.get(0).getPetals() * 3);
assertEquals(anotherList.size(), flowers.size());
Assert.assertTrue(anotherList.containsAll(flowers));
}
@Test
public void givenAListAndElements_whenUseCollectionsAddAll_thenAddElementsToTargetList() {
List<Flower> target = new ArrayList<>();
Collections.addAll(target, flowers.get(0), flowers.get(1), flowers.get(2), flowers.get(0));
assertEquals(target.size(), 4);
}
@Test
public void givenTwoList_whenSourceListDoesNotHaveNullElements_thenAddElementsToTargetListSkipFirstElementByStreamProcess() {
List<Flower> flowerVase = new ArrayList<>();
flowers.stream()
.skip(1)
.forEachOrdered(flowerVase::add);
assertEquals(flowerVase.size() + 1, flowers.size());
assertFalse(flowerVase.containsAll(flowers));
}
@Test
public void givenTwoList_whenSourceListDoesNotHaveNullElements_thenAddElementsToTargetListFilteringElementsByStreamProcess() {
List<Flower> flowerVase = new ArrayList<>();
flowers.stream()
.filter(f -> f.getPetals() > 10)
.forEachOrdered(flowerVase::add);
assertEquals(flowerVase.size() + 1, flowers.size());
assertFalse(flowerVase.containsAll(flowers));
}
@Test
public void givenAList_whenListIsNotNull_thenAddElementsToListByStreamProcessWihtOptional() {
List<Flower> target = new ArrayList<>();
Optional.ofNullable(flowers)
.ifPresent(target::addAll);
assertNotNull(target);
assertEquals(target.size(), 3);
}
}

View File

@ -19,11 +19,23 @@
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -50,6 +62,8 @@
<properties>
<!-- testing -->
<assertj.version>3.10.0</assertj.version>
<junit.platform.version>1.2.0</junit.platform.version>
<awaitility.version>1.7.0</awaitility.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>

View File

@ -0,0 +1,27 @@
package com.baeldung.java9.language.stream;
import static java.util.stream.Collectors.filtering;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class StreamsGroupingCollectionFilter {
static public Map<Integer, List<Integer>> findEvenNumbersAfterGroupingByQuantityOfDigits(Collection<Integer> baseCollection) {
Function<Integer, Integer> getQuantityOfDigits = item -> (int) Math.log10(item) + 1;
return baseCollection.stream()
.collect(groupingBy(getQuantityOfDigits, filtering(item -> item % 2 == 0, toList())));
}
static public Map<Integer, List<Integer>> findEvenNumbersBeforeGroupingByQuantityOfDigits(Collection<Integer> baseCollection) {
return baseCollection.stream()
.filter(item -> item % 2 == 0)
.collect(groupingBy(item -> (int) Math.log10(item) + 1, toList()));
}
}

View File

@ -0,0 +1,51 @@
package com.baeldung.java9.language.stream;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
public class CollectionFilterUnitTest {
private static final Collection<Integer> BASE_INTEGER_COLLECTION = Arrays.asList(9, 12, 55, 56, 101, 115, 8002, 223, 2668, 19, 8);
private static final Map<Integer, List<Integer>> EXPECTED_EVEN_FILTERED_AFTER_GROUPING_MAP = createExpectedFilterAfterGroupingMap();
private static Map<Integer, List<Integer>> createExpectedFilterAfterGroupingMap() {
Map<Integer, List<Integer>> map = new HashMap<>();
map.put(1, Arrays.asList(8));
map.put(2, Arrays.asList(12, 56));
map.put(3, Collections.emptyList());
map.put(4, Arrays.asList(8002, 2668));
return map;
}
private static final Map<Integer, List<Integer>> EXPECTED_EVEN_FILTERED_BEFORE_GROUPING_MAP = createExpectedFilterBeforeGroupingMap();
private static Map<Integer, List<Integer>> createExpectedFilterBeforeGroupingMap() {
Map<Integer, List<Integer>> map = new HashMap<>();
map.put(1, Arrays.asList(8));
map.put(2, Arrays.asList(12, 56));
map.put(4, Arrays.asList(8002, 2668));
return map;
}
@Test
public void givenAStringCollection_whenFilteringFourLetterWords_thenObtainTheFilteredCollection() {
Map<Integer, List<Integer>> filteredAfterGroupingMap = StreamsGroupingCollectionFilter.findEvenNumbersAfterGroupingByQuantityOfDigits(BASE_INTEGER_COLLECTION);
Map<Integer, List<Integer>> filteredBeforeGroupingMap = StreamsGroupingCollectionFilter.findEvenNumbersBeforeGroupingByQuantityOfDigits(BASE_INTEGER_COLLECTION);
assertThat(filteredAfterGroupingMap).containsAllEntriesOf(EXPECTED_EVEN_FILTERED_AFTER_GROUPING_MAP);
assertThat(filteredBeforeGroupingMap).doesNotContainKey(3)
.containsAllEntriesOf(EXPECTED_EVEN_FILTERED_BEFORE_GROUPING_MAP);
}
}

View File

@ -30,3 +30,4 @@
- [How to TDD a List Implementation in Java](http://www.baeldung.com/java-test-driven-list)
- [How to Store Duplicate Keys in a Map in Java?](http://www.baeldung.com/java-map-duplicate-keys)
- [Getting the Size of an Iterable in Java](http://www.baeldung.com/java-iterable-size)
- [Iterating Backward Through a List](http://www.baeldung.com/java-list-iterate-backwards)

View File

@ -36,19 +36,37 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
<version>${eclipse.collections.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
<version>${eclipse.collections.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<junit.platform.version>1.2.0</junit.platform.version>
<commons-lang3.version>3.5</commons-lang3.version>
<commons-collections4.version>4.1</commons-collections4.version>
<collections-generic.version>4.01</collections-generic.version>
<avaitility.version>1.7.0</avaitility.version>
<assertj.version>3.6.1</assertj.version>
<eclipse.collections.version>9.2.0</eclipse.collections.version>
</properties>
</project>

View File

@ -0,0 +1,16 @@
package com.baeldung.java.filtering;
import java.util.Collection;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
public class CollectionUtilsCollectionFilter {
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
Predicate<Integer> apacheEventNumberPredicate = item -> item % 2 == 0;
CollectionUtils.filter(baseCollection, apacheEventNumberPredicate);
return baseCollection;
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.java.filtering;
import java.util.Collection;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.utility.Iterate;
public class EclipseCollectionsCollectionFilter {
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
Predicate<Integer> eclipsePredicate = item -> item % 2 == 0;
Collection<Integer> filteredList = Lists.mutable.ofAll(baseCollection)
.select(eclipsePredicate);
return filteredList;
}
static public Collection<Integer> findEvenNumbersUsingIterate(Collection<Integer> baseCollection) {
Predicate<Integer> eclipsePredicate = new Predicate<Integer>() {
private static final long serialVersionUID = 1L;
@Override
public boolean accept(Integer arg0) {
return arg0 % 2 == 0;
}
};
Collection<Integer> filteredList = Iterate.select(baseCollection, eclipsePredicate);
return filteredList;
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.java.filtering;
import java.util.Collection;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
public class GuavaCollectionFilter {
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
Predicate<Integer> guavaPredicate = item -> item % 2 == 0;
Collection<Integer> filteredCollection = Collections2.filter(baseCollection, guavaPredicate);
return filteredCollection;
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.java.filtering;
import java.util.Collection;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class StreamsCollectionFilter {
public static <T> Collection<T> filterCollectionHelperMethod(Collection<T> baseCollection, Predicate<T> predicate) {
return baseCollection.stream()
.filter(predicate)
.collect(Collectors.toList());
}
static public Collection<Integer> findEvenNumbersUsingHelperMethod(Collection<Integer> baseCollection) {
return filterCollectionHelperMethod(baseCollection, item -> item % 2 == 0);
}
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
Predicate<Integer> streamsPredicate = item -> item % 2 == 0;
return baseCollection.stream()
.filter(streamsPredicate)
.collect(Collectors.toList());
}
}

View File

@ -0,0 +1,44 @@
package com.baeldung.java.filtering;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
public class CollectionFiltersUnitTest {
private static final Collection<Integer> BASE_INTEGER_COLLECTION = Arrays.asList(9, 14, 2, 7, 1, 5, 8);
private static final Collection<Integer> EXPECTED_EVEN_FILTERED_COLLECTION = Arrays.asList(14, 2, 8);
@Test
public void givenAStringCollection_whenFilteringFourLetterWords_thenObtainTheFilteredCollection() {
final Collection<String> baseStrings = Arrays.asList("java", "baeldung", "type", "example", "other");
Collection<String> filtered = StreamsCollectionFilter.filterCollectionHelperMethod(baseStrings, item -> item.length() == 4);
assertThat(filtered).containsExactlyInAnyOrder("java", "type");
}
@Test
public void givenAnIntegerCollection_whenFilteringEvenValues_thenObtainTheFilteredCollectionForAllCases() {
Collection<Integer> filteredWithStreams1 = StreamsCollectionFilter.findEvenNumbers(BASE_INTEGER_COLLECTION);
Collection<Integer> filteredWithCollectionUtils = CollectionUtilsCollectionFilter.findEvenNumbers(new ArrayList<>(BASE_INTEGER_COLLECTION));
Collection<Integer> filteredWithEclipseCollections = EclipseCollectionsCollectionFilter.findEvenNumbers(BASE_INTEGER_COLLECTION);
Collection<Integer> filteredWithEclipseCollectionsUsingIterate = EclipseCollectionsCollectionFilter.findEvenNumbersUsingIterate(BASE_INTEGER_COLLECTION);
Collection<Integer> filteredWithGuava = GuavaCollectionFilter.findEvenNumbers(BASE_INTEGER_COLLECTION);
assertThat(filteredWithStreams1).hasSameElementsAs(filteredWithCollectionUtils)
.hasSameElementsAs(filteredWithEclipseCollections)
.hasSameElementsAs(filteredWithEclipseCollectionsUsingIterate)
.hasSameElementsAs(filteredWithEclipseCollectionsUsingIterate)
.hasSameElementsAs(filteredWithGuava)
.hasSameElementsAs(EXPECTED_EVEN_FILTERED_COLLECTION);
}
}

View File

@ -0,0 +1,51 @@
package com.baeldung.list.removefirst;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class RemoveFirstElementUnitTest {
private List<String> list = new ArrayList<>();
private LinkedList<String> linkedList = new LinkedList<>();
@Before
public void init() {
list.add("cat");
list.add("dog");
list.add("pig");
list.add("cow");
list.add("goat");
linkedList.add("cat");
linkedList.add("dog");
linkedList.add("pig");
linkedList.add("cow");
linkedList.add("goat");
}
@Test
public void givenList_whenRemoveFirst_thenRemoved() {
list.remove(0);
assertThat(list, hasSize(4));
assertThat(list, not(contains("cat")));
}
@Test
public void givenLinkedList_whenRemoveFirst_thenRemoved() {
linkedList.removeFirst();
assertThat(linkedList, hasSize(4));
assertThat(linkedList, not(contains("cat")));
}
}

View File

@ -28,3 +28,5 @@
- [Guide to Java NIO2 Asynchronous Channel APIs](http://www.baeldung.com/java-nio-2-async-channels)
- [A Guide to NIO2 Asynchronous Socket Channel](http://www.baeldung.com/java-nio2-async-socket-channel)
- [Download a File From an URL in Java](http://www.baeldung.com/java-download-file)
- [Create a Symbolic Link with Java](http://www.baeldung.com/java-symlink)
- [Quick Use of FilenameFilter](http://www.baeldung.com/java-filename-filter)

View File

@ -0,0 +1,59 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.core-java-persistence</groupId>
<artifactId>core-java-persistence</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>core-java-persistence</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2database.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>${commons-dbcp2.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${HikariCP.version}</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
</dependencies>
<build>
<finalName>core-java-persistence</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<properties>
<assertj-core.version>3.10.0</assertj-core.version>
<h2database.version>1.4.197</h2database.version>
<commons-dbcp2.version>2.4.0</commons-dbcp2.version>
<HikariCP.version>3.2.0</HikariCP.version>
<c3p0.version>0.9.5.2</c3p0.version>
</properties>
</project>

View File

@ -1,85 +1,92 @@
package com.baeldung.connectionpool.connectionpools;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BasicConnectionPool implements ConnectionPool {
private final String url;
private final String user;
private final String password;
private final List<Connection> connectionPool;
private final List<Connection> usedConnections = new ArrayList<>();
private static final int INITIAL_POOL_SIZE = 10;
private final int MAX_POOL_SIZE = 20;
public static BasicConnectionPool create(String url, String user, String password) throws SQLException {
List<Connection> pool = new ArrayList<>(INITIAL_POOL_SIZE);
for (int i = 0; i < INITIAL_POOL_SIZE; i++) {
pool.add(createConnection(url, user, password));
}
return new BasicConnectionPool(url, user, password, pool);
}
private BasicConnectionPool(String url, String user, String password, List<Connection> connectionPool) {
this.url = url;
this.user = user;
this.password = password;
this.connectionPool = connectionPool;
}
@Override
public Connection getConnection() throws SQLException {
if (connectionPool.isEmpty()) {
if (usedConnections.size() < MAX_POOL_SIZE) {
connectionPool.add(createConnection(url, user, password));
} else {
throw new RuntimeException("Maximum pool size reached, no available connections!");
}
}
Connection connection = connectionPool.remove(connectionPool.size() - 1);
usedConnections.add(connection);
return connection;
}
@Override
public boolean releaseConnection(Connection connection) {
connectionPool.add(connection);
return usedConnections.remove(connection);
}
private static Connection createConnection(String url, String user, String password) throws SQLException {
return DriverManager.getConnection(url, user, password);
}
public int getSize() {
return connectionPool.size() + usedConnections.size();
}
@Override
public String getUrl() {
return url;
}
@Override
public String getUser() {
return user;
}
@Override
public String getPassword() {
return password;
}
public void shutdown() throws SQLException {
usedConnections.forEach(this::releaseConnection);
for (Connection c : connectionPool) {
c.close();
}
connectionPool.clear();
}
}
package com.baeldung.connectionpool;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BasicConnectionPool implements ConnectionPool {
private final String url;
private final String user;
private final String password;
private final List<Connection> connectionPool;
private final List<Connection> usedConnections = new ArrayList<>();
private static final int INITIAL_POOL_SIZE = 10;
private final int MAX_POOL_SIZE = 20;
public static BasicConnectionPool create(String url, String user, String password) throws SQLException {
List<Connection> pool = new ArrayList<>(INITIAL_POOL_SIZE);
for (int i = 0; i < INITIAL_POOL_SIZE; i++) {
pool.add(createConnection(url, user, password));
}
return new BasicConnectionPool(url, user, password, pool);
}
private BasicConnectionPool(String url, String user, String password, List<Connection> connectionPool) {
this.url = url;
this.user = user;
this.password = password;
this.connectionPool = connectionPool;
}
@Override
public Connection getConnection() throws SQLException {
if (connectionPool.isEmpty()) {
if (usedConnections.size() < MAX_POOL_SIZE) {
connectionPool.add(createConnection(url, user, password));
} else {
throw new RuntimeException("Maximum pool size reached, no available connections!");
}
}
Connection connection = connectionPool.remove(connectionPool.size() - 1);
usedConnections.add(connection);
return connection;
}
@Override
public boolean releaseConnection(Connection connection) {
connectionPool.add(connection);
return usedConnections.remove(connection);
}
private static Connection createConnection(String url, String user, String password) throws SQLException {
return DriverManager.getConnection(url, user, password);
}
@Override
public int getSize() {
return connectionPool.size() + usedConnections.size();
}
@Override
public List<Connection> getConnectionPool() {
return connectionPool;
}
@Override
public String getUrl() {
return url;
}
@Override
public String getUser() {
return user;
}
@Override
public String getPassword() {
return password;
}
@Override
public void shutdown() throws SQLException {
usedConnections.forEach(this::releaseConnection);
for (Connection c : connectionPool) {
c.close();
}
connectionPool.clear();
}
}

View File

@ -1,28 +1,28 @@
package com.baeldung.connectionpool.connectionpools;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
public class C3poDataSource {
private static final ComboPooledDataSource cpds = new ComboPooledDataSource();
static {
try {
cpds.setDriverClass("org.h2.Driver");
cpds.setJdbcUrl("jdbc:h2:mem:test");
cpds.setUser("user");
cpds.setPassword("password");
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return cpds.getConnection();
}
private C3poDataSource(){}
package com.baeldung.connectionpool;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
public class C3poDataSource {
private static final ComboPooledDataSource cpds = new ComboPooledDataSource();
static {
try {
cpds.setDriverClass("org.h2.Driver");
cpds.setJdbcUrl("jdbc:h2:mem:test");
cpds.setUser("user");
cpds.setPassword("password");
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return cpds.getConnection();
}
private C3poDataSource(){}
}

View File

@ -1,18 +1,24 @@
package com.baeldung.connectionpool.connectionpools;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public interface ConnectionPool {
Connection getConnection() throws SQLException;
boolean releaseConnection(Connection connection);
String getUrl();
String getUser();
String getPassword();
package com.baeldung.connectionpool;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public interface ConnectionPool {
Connection getConnection() throws SQLException;
boolean releaseConnection(Connection connection);
List<Connection> getConnectionPool();
int getSize();
String getUrl();
String getUser();
String getPassword();
void shutdown() throws SQLException;;
}

View File

@ -1,25 +1,25 @@
package com.baeldung.connectionpool.connectionpools;
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.dbcp2.BasicDataSource;
public class DBCPDataSource {
private static final BasicDataSource ds = new BasicDataSource();
static {
ds.setUrl("jdbc:h2:mem:test");
ds.setUsername("user");
ds.setPassword("password");
ds.setMinIdle(5);
ds.setMaxIdle(10);
ds.setMaxOpenPreparedStatements(100);
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
private DBCPDataSource(){}
}
package com.baeldung.connectionpool;
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.dbcp2.BasicDataSource;
public class DBCPDataSource {
private static final BasicDataSource ds = new BasicDataSource();
static {
ds.setUrl("jdbc:h2:mem:test");
ds.setUsername("user");
ds.setPassword("password");
ds.setMinIdle(5);
ds.setMaxIdle(10);
ds.setMaxOpenPreparedStatements(100);
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
private DBCPDataSource(){}
}

View File

@ -1,28 +1,28 @@
package com.baeldung.connectionpool.connectionpools;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class HikariCPDataSource {
private static final HikariConfig config = new HikariConfig();
private static final HikariDataSource ds;
static {
config.setJdbcUrl("jdbc:h2:mem:test");
config.setUsername("user");
config.setPassword("password");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
ds = new HikariDataSource(config);
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
private HikariCPDataSource(){}
}
package com.baeldung.connectionpool;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class HikariCPDataSource {
private static final HikariConfig config = new HikariConfig();
private static final HikariDataSource ds;
static {
config.setJdbcUrl("jdbc:h2:mem:test");
config.setUsername("user");
config.setPassword("password");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
ds = new HikariDataSource(config);
}
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
private HikariCPDataSource(){}
}

View File

@ -1,10 +1,8 @@
package com.baeldung.connectionpool;
import com.baeldung.connectionpool.connectionpools.BasicConnectionPool;
import com.baeldung.connectionpool.connectionpools.ConnectionPool;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

View File

@ -1,6 +1,5 @@
package com.baeldung.connectionpool;
import com.baeldung.connectionpool.connectionpools.C3poDataSource;
import java.sql.SQLException;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

View File

@ -1,6 +1,5 @@
package com.baeldung.connectionpool;
import com.baeldung.connectionpool.connectionpools.DBCPDataSource;
import java.sql.SQLException;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

View File

@ -1,6 +1,5 @@
package com.baeldung.connectionpool;
import com.baeldung.connectionpool.connectionpools.HikariCPDataSource;
import java.sql.SQLException;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

View File

@ -163,3 +163,8 @@
- [Console I/O in Java](http://www.baeldung.com/java-console-input-output)
- [Guide to the java.util.Arrays Class](http://www.baeldung.com/java-util-arrays)
- [Create a Custom Exception in Java](http://www.baeldung.com/java-new-custom-exception)
- [Guide to java.util.GregorianCalendar](http://www.baeldung.com/java-gregorian-calendar)
- [Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler)
- [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream)
- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)
- [Exception Handling in Java](http://www.baeldung.com/java-exceptions)

View File

@ -158,21 +158,6 @@
<artifactId>jmimemagic</artifactId>
<version>${jmime-magic.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>${commons-dbcp2.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${HikariCP.version}</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
<!-- instrumentation -->
<dependency>
<groupId>org.javassist</groupId>
@ -544,11 +529,6 @@
<!-- testing -->
<assertj-core.version>3.10.0</assertj-core.version>
<!-- JDBC pooling frameworks -->
<commons-dbcp2.version>2.4.0</commons-dbcp2.version>
<HikariCP.version>3.2.0</HikariCP.version>
<c3p0.version>0.9.5.2</c3p0.version>
<!-- maven plugins -->
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<springframework.spring-web.version>4.3.4.RELEASE</springframework.spring-web.version>

View File

@ -34,3 +34,5 @@
- [Java EE 8 Security API](http://www.baeldung.com/java-ee-8-security)
- [Kotlin with Ktor](http://www.baeldung.com/kotlin-ktor)
- [Working with Enums in Kotlin](http://www.baeldung.com/kotlin-enum)
- [Create a Java and Kotlin Project with Maven](http://www.baeldung.com/kotlin-maven-java-project)
- [Reflection with Kotlin](http://www.baeldung.com/kotlin-reflection)

View File

@ -0,0 +1,2 @@
### Relevant Articles:
- [Introduction to GWT](http://www.baeldung.com/gwt)

View File

@ -6,10 +6,16 @@
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>google-web-toolkit</artifactId>
<artifactId>google_web_toolkit</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<!-- ensure all GWT deps use the same version (unless overridden) -->

View File

@ -22,6 +22,8 @@
<!-- Specify the app entry point class. -->
<entry-point class='com.baeldung.client.Google_web_toolkit'/>
<set-property name="user.agent" value="gecko1_8"/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>

View File

@ -85,7 +85,7 @@
- [Implementing a FTP-Client in Java](http://www.baeldung.com/java-ftp-client)
- [Convert String to Date in Java](http://www.baeldung.com/java-string-to-date)
- [Histograms with Apache Commons Frequency](http://www.baeldung.com/apache-commons-frequency)
- [Guide to Resilience4j](http://www.baeldung.com/resilience4j)
The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own.

View File

@ -18,6 +18,13 @@
<artifactId>log4j-core</artifactId>
<version>${log4j-core.version}</version>
</dependency>
<!-- This is the needed API component. -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-core.version}</version>
</dependency>
<!-- This is used by JSONLayout. -->
<dependency>
@ -114,4 +121,4 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>
</project>
</project>

View File

@ -0,0 +1,54 @@
/**
*
*/
package com.baeldung.logging.log4j2.appender;
import java.time.Instant;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Core;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
@Plugin(name = "MapAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
public class MapAppender extends AbstractAppender {
private ConcurrentMap<String, LogEvent> eventMap = new ConcurrentHashMap<>();
protected MapAppender(String name, Filter filter) {
super(name, filter, null);
}
@PluginFactory
public static MapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filter") final Filter filter) {
return new MapAppender(name, filter);
}
@Override
public void append(LogEvent event) {
if (event.getLevel()
.isLessSpecificThan(Level.WARN)) {
error("Unable to log less than WARN level.");
return;
}
eventMap.put(Instant.now()
.toString(), event);
}
public ConcurrentMap<String, LogEvent> getEventMap() {
return eventMap;
}
public void setEventMap(ConcurrentMap<String, LogEvent> eventMap) {
this.eventMap = eventMap;
}
}

View File

@ -0,0 +1,35 @@
package com.baeldung.logging.log4j2.appender;
import static org.junit.Assert.assertEquals;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class MapAppenderIntegrationTest {
private Logger logger;
@Before
public void setup() {
logger = LogManager.getLogger(MapAppenderIntegrationTest.class);
}
@Test
public void whenLoggerEmitsLoggingEvent_thenAppenderReceivesEvent() throws Exception {
logger.info("Test from {}", this.getClass()
.getSimpleName());
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
MapAppender appender = config.getAppender("MapAppender");
assertEquals(appender.getEventMap()
.size(), 1);
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns:xi="http://www.w3.org/2001/XInclude"
status="WARN">
<Configuration xmlns:xi="http://www.w3.org/2001/XInclude"
packages="com.baeldung" status="WARN">
<Appenders>
<xi:include
href="log4j2-includes/console-appender_pattern-layout_colored.xml" />
@ -50,6 +50,7 @@
size="17 kB" />
</Policies>
</RollingFile>
<MapAppender name="MapAppender"/>
</Appenders>
<Loggers>
<Logger name="CONSOLE_PATTERN_APPENDER_MARKER" level="TRACE"
@ -82,6 +83,7 @@
</Logger>
<Root level="DEBUG">
<AppenderRef ref="ConsoleAppender" />
<AppenderRef ref="MapAppender" />
</Root>
</Loggers>
</Configuration>

View File

@ -1,4 +1,4 @@
###Relevant Articles:
### Relevant Articles:
- [A Guide to the Front Controller Pattern in Java](http://www.baeldung.com/java-front-controller-pattern)
- [Introduction to Intercepting Filter Pattern in Java](http://www.baeldung.com/intercepting-filter-pattern-in-java)
- [Implementing the Template Method Pattern in Java](http://www.baeldung.com/java-template-method-pattern)

View File

@ -10,3 +10,4 @@
- [Composite Design Pattern in Java](http://www.baeldung.com/java-composite-pattern)
- [Visitor Design Pattern in Java](http://www.baeldung.com/java-visitor-pattern)
- [The DAO Pattern in Java](http://www.baeldung.com/java-dao-pattern)
- [Interpreter Design Pattern in Java](http://www.baeldung.com/java-interpreter-pattern)

39
pom.xml
View File

@ -312,6 +312,7 @@
<module>core-java-collections</module>
<module>core-java-io</module>
<module>core-java-8</module>
<module>core-java-persistence</module>
<module>core-kotlin</module>
<module>core-groovy</module>
<module>core-java-concurrency</module>
@ -858,7 +859,7 @@
<module>core-java-io</module>
<module>core-java-8</module>
<module>core-groovy</module>
<module>core-java-concurrency</module>
<module>couchbase</module>
<module>deltaspike</module>
<module>dozer</module>
@ -877,7 +878,7 @@
<module>spring-static-resources</module>
<module>hazelcast</module>
<module>hbase</module>
<module>httpclient</module>
<module>hystrix</module>
<module>image-processing</module>
<module>immutables</module>
@ -906,11 +907,11 @@
<module>linkrest</module>
<module>logging-modules/log-mdc</module>
<module>logging-modules/log4j</module>
<module>logging-modules/log4j2</module>
<module>logging-modules/logback</module>
<module>lombok</module>
<module>mapstruct</module>
<module>metrics</module>
<module>maven</module>
<module>mesos-marathon</module>
<module>msf4j</module>
@ -962,25 +963,25 @@
<module>spring-cucumber</module>
<module>spring-ejb</module>
<module>spring-aop</module>
<module>spring-data-couchbase-2</module>
<module>persistence-modules/spring-data-dynamodb</module>
<module>spring-data-keyvalue</module>
<module>spring-data-mongodb</module>
<module>persistence-modules/spring-data-neo4j</module>
<module>persistence-modules/spring-data-redis</module>
<module>spring-data-rest</module>
<module>persistence-modules/spring-data-solr</module>
<module>spring-dispatcher-servlet</module>
<module>spring-exceptions</module>
<module>spring-freemarker</module>
<module>persistence-modules/spring-hibernate-3</module>
<module>spring-hibernate4</module>
<module>persistence-modules/spring-hibernate-5</module>
<module>persistence-modules/spring-data-eclipselink</module>
<module>spring-integration</module>
<module>spring-jenkins-pipeline</module>
<module>spring-jersey</module>
<module>jmeter</module>
<module>spring-jms</module>
<module>spring-jooq</module>
<module>persistence-modules/spring-jpa</module>
@ -1041,13 +1042,13 @@
<module>testing-modules/testing</module>
<module>testing-modules/testng</module>
<module>video-tutorials</module>
<module>xml</module>
<module>xmlunit-2</module>
<module>struts-2</module>
<module>apache-velocity</module>
<module>apache-solrj</module>
<module>rabbitmq</module>
<module>vertx</module>
<module>persistence-modules/spring-data-gemfire</module>
<module>mybatis</module>
<module>spring-drools</module>
@ -1077,11 +1078,22 @@
<module>apache-meecrowave</module>
<module>testing-modules/junit-abstract</module>
<module>spring-hibernate4</module>
<module>xml</module>
<module>vertx</module>
<module>metrics</module>
<module>httpclient</module>
<!-- problematic -->
<!--
<module>ejb</module>
<module>persistence-modules/java-cassandra</module>
<module>persistence-modules/spring-data-cassandra</module>
<module>logging-modules/log4j2</module>
<module>spring-data-couchbase-2</module>
<module>persistence-modules/spring-data-redis</module>
<module>jmeter</module>
-->
<!-- heavy -->
@ -1097,6 +1109,7 @@
<module>core-java</module>
<module>google-web-toolkit</module>
<module>spring-security-mvc-custom</module>
<module>core-java-concurrency</module>
-->
<!-- 30:32 min -->
@ -1159,7 +1172,7 @@
<module>spring-security-mvc-custom</module>
<module>hibernate5</module>
<module>spring-data-elasticsearch</module>
<module>core-java-concurrency</module>
</modules>
</profile>
@ -1223,6 +1236,4 @@
<!-- <maven-pmd-plugin.version>3.9.0</maven-pmd-plugin.version> -->
<maven-pmd-plugin.version>3.8</maven-pmd-plugin.version>
</properties>
</project>
</project>

View File

@ -15,3 +15,4 @@
- [RxJava Maybe](http://www.baeldung.com/rxjava-maybe)
- [Introduction to RxRelay for RxJava](http://www.baeldung.com/rx-relay)
- [Filtering Observables in RxJava](http://www.baeldung.com/rxjava-filtering)
- [RxJava One Observable, Multiple Subscribers](http://www.baeldung.com/rxjava-multiple-subscribers-observable)

View File

@ -5,16 +5,11 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles
- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests)
- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web)
- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching)
- [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient)
- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans)
- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config)
- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive)
- [Spring 5 Testing with @EnabledIf Annotation](https://github.com/eugenp/tutorials/tree/master/spring-5)
- [Reactive WebSockets with Spring 5](http://www.baeldung.com/spring-5-reactive-websockets)
- [Spring Boot Actuator](http://www.baeldung.com/spring-boot-actuators)
- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching)
- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive)
- [Reactive WebSockets with Spring 5](http://www.baeldung.com/spring-5-reactive-websockets)
- [Spring Webflux Filters](http://www.baeldung.com/spring-webflux-filters)
- [Reactive Flow with MongoDB, Kotlin, and Spring WebFlux](http://www.baeldung.com/kotlin-mongodb-spring-webflux)
- [Spring Data Reactive Repositories with MongoDB](http://www.baeldung.com/spring-data-mongodb-reactive)
- [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header)

View File

@ -127,15 +127,6 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>

View File

@ -0,0 +1,23 @@
package com.baeldung.functional;
class Actor {
private String firstname;
private String lastname;
public Actor() {
}
public Actor(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
}

View File

@ -1,11 +1,9 @@
package com.baeldung.reactive;
import com.mongodb.reactivestreams.client.MongoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
@SpringBootApplication
public class Spring5ReactiveApplication{
@ -14,12 +12,4 @@ public class Spring5ReactiveApplication{
SpringApplication.run(Spring5ReactiveApplication.class, args);
}
@Autowired
MongoClient mongoClient;
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
return new ReactiveMongoTemplate(mongoClient, "test");
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung;
package com.baeldung.reactive;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

View File

@ -0,0 +1,28 @@
package com.baeldung.reactive.actuator;
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {
@Bean
public SecurityWebFilterChain securitygWebFilterChain(
ServerHttpSecurity http) {
return http
.authorizeExchange()
.matchers(EndpointRequest.to(
FeaturesEndpoint.class
)).permitAll().and().csrf().disable().build();
}
}

View File

@ -4,16 +4,8 @@ import java.util.Collections;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration;
@SpringBootApplication(exclude = { MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class,
MongoReactiveDataAutoConfiguration.class,
MongoReactiveAutoConfiguration.class }
)
@SpringBootApplication
public class CorsOnAnnotatedElementsApplication {
public static void main(String[] args) {

View File

@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("/web-filter-and-more-on-annotated")
//@RestController
//@RequestMapping("/web-filter-and-more-on-annotated")
public class FurtherCorsConfigsController {
@DeleteMapping("/further-mixed-config-endpoint")

View File

@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("/web-filter-on-annotated")
//@RestController
//@RequestMapping("/web-filter-on-annotated")
public class RegularRestController {
@PutMapping("/regular-put-endpoint")

View File

@ -1,4 +1,4 @@
package com.baeldung.security;
package com.baeldung.reactive.security;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

View File

@ -1,4 +1,4 @@
package com.baeldung.security;
package com.baeldung.reactive.security;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;

View File

@ -1,5 +1,6 @@
package com.baeldung.security;
package com.baeldung.reactive.security;
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
@ -9,6 +10,8 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.server.SecurityWebFilterChain;
import com.baeldung.reactive.actuator.FeaturesEndpoint;
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class SecurityConfig {
@ -16,25 +19,33 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
return http.authorizeExchange()
.pathMatchers("/admin").hasAuthority("ROLE_ADMIN")
.anyExchange().authenticated()
.and().formLogin()
.and().build();
.pathMatchers("/admin")
.hasAuthority("ROLE_ADMIN")
.matchers(EndpointRequest.to(FeaturesEndpoint.class))
.permitAll()
.anyExchange()
.permitAll()
.and()
.formLogin()
.and()
.csrf()
.disable()
.build();
}
@Bean
public MapReactiveUserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
.username("user")
.password("password")
.roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder()
.username("admin")
.password("password")
.roles("ADMIN")
.build();
.username("admin")
.password("password")
.roles("ADMIN")
.build();
return new MapReactiveUserDetailsService(user, admin);
}

View File

@ -1,4 +1,4 @@
package com.baeldung.reactive.websocket;
package com.baeldung.websocket;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package com.baeldung.reactive.websocket;
package com.baeldung.websocket;
import java.net.URI;
import java.time.Duration;

View File

@ -1,4 +1,4 @@
package com.baeldung.reactive.websocket;
package com.baeldung.websocket;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -1,4 +1,4 @@
package com.baeldung.reactive.websocket;
package com.baeldung.websocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

View File

@ -1,4 +1,4 @@
package com.baeldung.reactive.websocket;
package com.baeldung.websocket;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

View File

@ -1,6 +1,5 @@
package com.baeldung.jupiter;
package com.baeldung.reactive;
import com.baeldung.web.reactive.Task;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.http.server.reactive.HttpHandler;
@ -8,6 +7,9 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import com.baeldung.web.reactive.Task;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.ipc.netty.NettyContext;

View File

@ -15,13 +15,15 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import com.baeldung.reactive.Spring5ReactiveApplication;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes=Spring5ReactiveApplication.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class EmployeeControllerUnitTest {
public class EmployeeControllerIntegrationTest {
@Autowired
private WebTestClient testClient;

View File

@ -1,6 +1,6 @@
package com.baeldung.security;
import com.baeldung.SpringSecurity5Application;
import com.baeldung.reactive.SpringSecurity5Application;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

View File

@ -1,11 +1,10 @@
package com.baeldung.web.client;
import com.baeldung.Spring5Application;
import com.baeldung.reactive.Spring5ReactiveApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.server.RequestPredicates;
@ -16,8 +15,7 @@ import org.springframework.web.server.WebHandler;
import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableJpaRepositories("com.baeldung.persistence")
@SpringBootTest(classes = Spring5ReactiveApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WebTestClientIntegrationTest {
@LocalServerPort

View File

@ -6,14 +6,9 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles
- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests)
- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web)
- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching)
- [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient)
- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans)
- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config)
- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive)
- [Spring 5 Testing with @EnabledIf Annotation](http://www.baeldung.com/spring-5-enabledIf)
- [Introduction to Spring REST Docs](http://www.baeldung.com/spring-rest-docs)
- [Spring Security 5 OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login)
- [Spring ResponseStatusException](http://www.baeldung.com/spring-response-status-exception)
- [Spring Assert Statements](http://www.baeldung.com/spring-assert)

View File

@ -33,19 +33,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>${reactor-spring.version}</version>
</dependency>
<dependency>
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
@ -139,11 +130,6 @@
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-webtestclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-restassured</artifactId>

View File

@ -2,10 +2,8 @@ package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = { "com.baeldung.web" })
public class Spring5Application {
public static void main(String[] args) {

View File

@ -0,0 +1,12 @@
package com.baeldung.config;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@Configuration
@EnableJpaRepositories("com.baeldung.persistence")
@EntityScan("com.baeldung.web")
public class PersistenceConfig {
}

View File

@ -1,4 +1,4 @@
package com.baeldung.execption;
package com.baeldung.exception;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

View File

@ -1,4 +1,4 @@
package com.baeldung.execption;
package com.baeldung.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

View File

@ -1,4 +1,4 @@
package com.baeldung.execption;
package com.baeldung.exception;
import java.util.Arrays;
import java.util.List;

View File

@ -1,14 +1,14 @@
package com.baeldung.execption;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan(basePackages = { "com.baeldung.execption" })
public class SpringExceptionApplication {
public static void main(String[] args) {
SpringApplication.run(SpringExceptionApplication.class, args);
}
package com.baeldung.exception;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan(basePackages = { "com.baeldung.execption" })
public class SpringExceptionApplication {
public static void main(String[] args) {
SpringApplication.run(SpringExceptionApplication.class, args);
}
}

View File

@ -0,0 +1,28 @@
package com.baeldung.jupiter;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Task {
private final String name;
private final int id;
public Task(@JsonProperty("name") String name, @JsonProperty("id") int id) {
this.name = name;
this.id = id;
}
public String getName() {
return this.name;
}
public int getId() {
return this.id;
}
@Override
public String toString() {
return "Task{" + "name='" + name + '\'' + ", id=" + id + '}';
}
}

View File

@ -1,6 +1,5 @@
package com.baeldung.jupiter;
import com.baeldung.web.reactive.Task;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

View File

@ -1,55 +1,55 @@
package com.baeldung.jdbc.autogenkey;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate;
import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert;
@RunWith(SpringRunner.class)
@Ignore
public class GetAutoGenKeyByJDBC {
@Configuration
@EnableAutoConfiguration
@PropertySource("classpath:autogenkey-db.properties")
@ComponentScan(basePackages = { "com.baeldung.jdbc.autogenkey.repository" })
public static class SpringConfig {
}
@Autowired
MessageRepositorySimpleJDBCInsert messageRepositorySimpleJDBCInsert;
@Autowired
MessageRepositoryJDBCTemplate messageRepositoryJDBCTemplate;
final String MESSAGE_CONTENT = "Test";
@Test
public void insertJDBC_whenLoadMessageByKey_thenGetTheSameMessage() {
long key = messageRepositoryJDBCTemplate.insert(MESSAGE_CONTENT);
String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key);
assertEquals(MESSAGE_CONTENT, loadedMessage);
}
@Test
public void insertSimpleInsert_whenLoadMessageKey_thenGetTheSameMessage() {
long key = messageRepositorySimpleJDBCInsert.insert(MESSAGE_CONTENT);
String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key);
assertEquals(MESSAGE_CONTENT, loadedMessage);
}
}
package com.baeldung.jdbc.autogenkey;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate;
import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert;
@RunWith(SpringRunner.class)
@Ignore
public class GetAutoGenKeyByJDBCIntTest {
@Configuration
@EnableAutoConfiguration
@PropertySource("classpath:autogenkey-db.properties")
@ComponentScan(basePackages = { "com.baeldung.jdbc.autogenkey.repository" })
public static class SpringConfig {
}
@Autowired
MessageRepositorySimpleJDBCInsert messageRepositorySimpleJDBCInsert;
@Autowired
MessageRepositoryJDBCTemplate messageRepositoryJDBCTemplate;
final String MESSAGE_CONTENT = "Test";
@Test
public void insertJDBC_whenLoadMessageByKey_thenGetTheSameMessage() {
long key = messageRepositoryJDBCTemplate.insert(MESSAGE_CONTENT);
String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key);
assertEquals(MESSAGE_CONTENT, loadedMessage);
}
@Test
public void insertSimpleInsert_whenLoadMessageKey_thenGetTheSameMessage() {
long key = messageRepositorySimpleJDBCInsert.insert(MESSAGE_CONTENT);
String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key);
assertEquals(MESSAGE_CONTENT, loadedMessage);
}
}

View File

@ -1,6 +1,5 @@
package com.baeldung.jupiter;
import com.baeldung.web.reactive.Task;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,6 +1,5 @@
package com.baeldung.jupiter;
import com.baeldung.web.reactive.Task;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -0,0 +1,22 @@
package org.baeldung.primary;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@Configuration
@ComponentScan(basePackages="org.baeldung.primary")
public class Config {
@Bean
public Employee JohnEmployee(){
return new Employee("John");
}
@Bean
@Primary
public Employee TonyEmployee(){
return new Employee("Tony");
}
}

View File

@ -0,0 +1,11 @@
package org.baeldung.primary;
import org.springframework.stereotype.Component;
@Component
public class DepartmentManager implements Manager {
@Override
public String getManagerName() {
return "Department manager";
}
}

View File

@ -0,0 +1,20 @@
package org.baeldung.primary;
/**
* Created by Gebruiker on 7/17/2018.
*/
public class Employee {
private String name;
public Employee(String name) {
this.name = name;
}
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
'}';
}
}

View File

@ -0,0 +1,14 @@
package org.baeldung.primary;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@Component
@Primary
public class GeneralManager implements Manager {
@Override
public String getManagerName() {
return "General manager";
}
}

View File

@ -0,0 +1,8 @@
package org.baeldung.primary;
/**
* Created by Gebruiker on 7/19/2018.
*/
public interface Manager {
String getManagerName();
}

View File

@ -0,0 +1,17 @@
package org.baeldung.primary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by Gebruiker on 7/19/2018.
*/@Service
public class ManagerService {
@Autowired
private Manager manager;
public Manager getManager() {
return manager;
}
}

View File

@ -0,0 +1,20 @@
package org.baeldung.primary;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class PrimaryApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context
= new AnnotationConfigApplicationContext(Config.class);
Employee employee = context.getBean(Employee.class);
System.out.println(employee);
ManagerService service = context.getBean(ManagerService.class);
Manager manager = service.getManager();
System.out.println(manager.getManagerName());
}
}

View File

@ -1,4 +1,11 @@
### Relevant Articles:
================================
- [Spring Boot Console Application](http://www.baeldung.com/spring-boot-console-app)
### Relevant Articles:
- [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy)
- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent)
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)
- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot)
- [Introduction to WebJars](http://www.baeldung.com/maven-webjars)
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper)
- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown)
- [Spring Boot Console Application](http://www.baeldung.com/spring-boot-console-app)

View File

@ -34,3 +34,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Spring Boot Exit Codes](http://www.baeldung.com/spring-boot-exit-codes)
- [Guide to the Favicon in Spring Boot](http://www.baeldung.com/spring-boot-favicon)
- [Spring Shutdown Callbacks](http://www.baeldung.com/spring-shutdown-callbacks)
- [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb)

View File

@ -0,0 +1,8 @@
## Spring Data Reactive Project
### The Course
The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles
- [Reactive Flow with MongoDB, Kotlin, and Spring WebFlux](http://www.baeldung.com/kotlin-mongodb-spring-webflux)
- [Spring Data Reactive Repositories with MongoDB](http://www.baeldung.com/spring-data-mongodb-reactive)

View File

@ -23,11 +23,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax.ws.rs-api.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
@ -54,34 +49,51 @@
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
<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.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Snapshot Repository</name>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
@ -89,21 +101,30 @@
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
<groupId>org.jetbrains.kotlin</groupId>
@ -124,6 +145,57 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially
by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially
by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
@ -132,6 +204,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.2.40</kotlin.version>
<junit.platform.version>1.0.0</junit.platform.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
</properties>
</project>

View File

@ -0,0 +1,25 @@
package com.baeldung.reactive;
import com.mongodb.reactivestreams.client.MongoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
@SpringBootApplication
public class Spring5ReactiveApplication{
public static void main(String[] args) {
SpringApplication.run(Spring5ReactiveApplication.class, args);
}
@Autowired
MongoClient mongoClient;
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
return new ReactiveMongoTemplate(mongoClient, "test");
}
}

View File

@ -4,6 +4,3 @@ import org.springframework.data.mongodb.core.mapping.Document
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
interface EventRepository : ReactiveMongoRepository<Event, String>
@Document
data class Event(val id: String, val name: String)

Some files were not shown because too many files have changed in this diff Show More