Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL_3301_testing_@ConfigurationProperties
This commit is contained in:
commit
7ad34458c9
|
@ -1,20 +0,0 @@
|
|||
package com.baeldung.array;
|
||||
|
||||
public class Find2ndLargestInArray {
|
||||
|
||||
public static int find2ndLargestElement(int[] array) {
|
||||
int maxElement = array[0];
|
||||
int secondLargestElement = -1;
|
||||
|
||||
for (int index = 0; index < array.length; index++) {
|
||||
if (maxElement <= array[index]) {
|
||||
secondLargestElement = maxElement;
|
||||
maxElement = array[index];
|
||||
} else if (secondLargestElement < array[index]) {
|
||||
secondLargestElement = array[index];
|
||||
}
|
||||
}
|
||||
return secondLargestElement;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.baeldung.array;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FindElementInArray {
|
||||
|
||||
public static boolean findGivenElementInArrayWithoutUsingStream(int[] array, int element) {
|
||||
boolean actualResult = false;
|
||||
|
||||
for (int index = 0; index < array.length; index++) {
|
||||
if (element == array[index]) {
|
||||
actualResult = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return actualResult;
|
||||
}
|
||||
|
||||
public static boolean findGivenElementInArrayUsingStream(int[] array, int element) {
|
||||
return Arrays.stream(array).filter(x -> element == x).findFirst().isPresent();
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.baeldung.array;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Find2ndLargestInArrayUnitTest {
|
||||
@Test
|
||||
public void givenAnIntArray_thenFind2ndLargestElement() {
|
||||
int[] array = { 1, 3, 24, 16, 87, 20 };
|
||||
int expected2ndLargest = 24;
|
||||
|
||||
int actualSecondLargestElement = Find2ndLargestInArray.find2ndLargestElement(array);
|
||||
|
||||
Assert.assertEquals(expected2ndLargest, actualSecondLargestElement);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.baeldung.array;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FindElementInArrayUnitTest {
|
||||
@Test
|
||||
public void givenAnIntArray_whenNotUsingStream_thenFindAnElement() {
|
||||
int[] array = { 1, 3, 4, 8, 19, 20 };
|
||||
int element = 19;
|
||||
boolean expectedResult = true;
|
||||
boolean actualResult = FindElementInArray.findGivenElementInArrayWithoutUsingStream(array, element);
|
||||
Assert.assertEquals(expectedResult, actualResult);
|
||||
|
||||
element = 78;
|
||||
expectedResult = false;
|
||||
actualResult = FindElementInArray.findGivenElementInArrayWithoutUsingStream(array, element);
|
||||
Assert.assertEquals(expectedResult, actualResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnIntArray_whenUsingStream_thenFindAnElement() {
|
||||
int[] array = { 15, 16, 12, 18 };
|
||||
int element = 16;
|
||||
boolean expectedResult = true;
|
||||
boolean actualResult = FindElementInArray.findGivenElementInArrayUsingStream(array, element);
|
||||
Assert.assertEquals(expectedResult, actualResult);
|
||||
|
||||
element = 20;
|
||||
expectedResult = false;
|
||||
actualResult = FindElementInArray.findGivenElementInArrayUsingStream(array, element);
|
||||
Assert.assertEquals(expectedResult, actualResult);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
## Spring Data Couchbase Tutorial Project
|
||||
|
||||
### Relevant Articles:
|
||||
- [Intro to Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase)
|
||||
- [Entity Validation, Optimistic Locking, and Query Consistency in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
|
||||
- [Multiple Buckets and Spatial View Queries in Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase-buckets-and-spatial-view-queries)
|
||||
- [Intro to Spring Data Couchbase](https://www.baeldung.com/spring-data-couchbase)
|
||||
- [Entity Validation, Optimistic Locking, and Query Consistency in Spring Data Couchbase](https://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
|
||||
- [Multiple Buckets and Spatial View Queries in Spring Data Couchbase](https://www.baeldung.com/spring-data-couchbase-buckets-and-spatial-view-queries)
|
||||
|
||||
### Overview
|
||||
This Maven project contains the Java code for Spring Data Couchbase
|
||||
|
@ -25,14 +25,14 @@ mvn clean install
|
|||
|
||||
### Package Organization
|
||||
Java classes for the first two tutorials listed above are in src/main/java in the package hierarchy
|
||||
org.baeldung.spring.data.couchbase
|
||||
com.baeldung.spring.data.couchbase
|
||||
|
||||
Java classes for the multiple-bucket tutorials are in src/main/java in the package hierarchy
|
||||
org.baeldung.spring.data.couchbase2b
|
||||
com.baeldung.spring.data.couchbase2b
|
||||
|
||||
### Running the tests
|
||||
The test classes for the single-bucket tutorials are in src/test/java in the package
|
||||
org.baeldung.spring.data.couchbase.service:
|
||||
com.baeldung.spring.data.couchbase.service:
|
||||
- PersonServiceTest (abstract)
|
||||
- PersonRepositoryTest (concrete)
|
||||
- PersonTemplateServiceTest (concrete)
|
||||
|
@ -41,7 +41,7 @@ org.baeldung.spring.data.couchbase.service:
|
|||
- StudentTemplateServiceTest (concrete)
|
||||
|
||||
The concrete test classes for the multiple-bucket tutorial are in src/test/java in the package
|
||||
org.baeldung.spring.data.couchbase2b.service:
|
||||
com.baeldung.spring.data.couchbase2b.service:
|
||||
- CampusRepositoryServiceImplTest
|
||||
- PersonRepositoryServiceImplTest
|
||||
- StudentRepositoryServiceImplTest
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
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>org.baeldung</groupId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-data-couchbase-2</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>spring-data-couchbase-2</name>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.model;
|
||||
package com.baeldung.spring.data.couchbase.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.model;
|
||||
package com.baeldung.spring.data.couchbase.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.model;
|
||||
package com.baeldung.spring.data.couchbase.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Past;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.repos;
|
||||
package com.baeldung.spring.data.couchbase.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
|
||||
public interface CustomStudentRepository {
|
||||
List<Student> findByFirstNameStartsWith(String s);
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.repos;
|
||||
package com.baeldung.spring.data.couchbase.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.couchbase.core.CouchbaseTemplate;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.repos;
|
||||
package com.baeldung.spring.data.couchbase.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, String> {
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.repos;
|
||||
package com.baeldung.spring.data.couchbase.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface StudentRepository extends CrudRepository<Student, String>, CustomStudentRepository {
|
|
@ -1,11 +1,11 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.baeldung.spring.data.couchbase.repos.PersonRepository;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.repos.PersonRepository;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
|
||||
public interface PersonService {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,11 +1,11 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.baeldung.spring.data.couchbase.repos.StudentRepository;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.repos.StudentRepository;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
|
||||
public interface StudentService {
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase2b.repos;
|
||||
package com.baeldung.spring.data.couchbase2b.repos;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Campus;
|
||||
import com.baeldung.spring.data.couchbase.model.Campus;
|
||||
import org.springframework.data.couchbase.core.query.Dimensional;
|
||||
import org.springframework.data.couchbase.core.query.View;
|
||||
import org.springframework.data.geo.Distance;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase2b.repos;
|
||||
package com.baeldung.spring.data.couchbase2b.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, String> {
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase2b.repos;
|
||||
package com.baeldung.spring.data.couchbase2b.repos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface StudentRepository extends CrudRepository<Student, String> {
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Campus;
|
||||
import com.baeldung.spring.data.couchbase.model.Campus;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Point;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Campus;
|
||||
import org.baeldung.spring.data.couchbase2b.repos.CampusRepository;
|
||||
import com.baeldung.spring.data.couchbase2b.repos.CampusRepository;
|
||||
import com.baeldung.spring.data.couchbase.model.Campus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Point;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
|
||||
public interface PersonService {
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.baeldung.spring.data.couchbase2b.repos.PersonRepository;
|
||||
import com.baeldung.spring.data.couchbase2b.repos.PersonRepository;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
|
||||
public interface StudentService {
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.baeldung.spring.data.couchbase2b.repos.StudentRepository;
|
||||
import com.baeldung.spring.data.couchbase2b.repos.StudentRepository;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketIntegrationTestConfig;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketIntegrationTestConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
@ -25,7 +25,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
|||
* {@code
|
||||
* function (doc) {
|
||||
* if (doc.location &&
|
||||
* doc._class == "org.baeldung.spring.data.couchbase.model.Campus") {
|
||||
* doc._class == "com.baeldung.spring.data.couchbase.model.Campus") {
|
||||
* emit([doc.location.x, doc.location.y], null);
|
||||
* }
|
||||
* }}
|
||||
|
@ -34,7 +34,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
|||
* 2.4.1- view 'all' with function:
|
||||
* {@code
|
||||
* function (doc, meta) {
|
||||
* if(doc._class == "org.baeldung.spring.data.couchbase.model.Campus") {
|
||||
* if(doc._class == "com.baeldung.spring.data.couchbase.model.Campus") {
|
||||
* emit(meta.id, null);
|
||||
* }
|
||||
* }}
|
||||
|
@ -42,7 +42,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
|||
* 2.4.2- view 'byName' with function:
|
||||
* {@code
|
||||
* function (doc, meta) {
|
||||
* if(doc._class == "org.baeldung.spring.data.couchbase.model.Campus" &&
|
||||
* if(doc._class == "com.baeldung.spring.data.couchbase.model.Campus" &&
|
||||
* doc.name) {
|
||||
* emit(doc.name, null);
|
||||
* }
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase;
|
||||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase;
|
||||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
|
@ -1,9 +1,9 @@
|
|||
package org.baeldung.spring.data.couchbase;
|
||||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "org.baeldung.spring.data.couchbase")
|
||||
@ComponentScan(basePackages = "com.baeldung.spring.data.couchbase")
|
||||
public class IntegrationTestConfig {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase;
|
||||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepos
|
|||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories(basePackages = { "org.baeldung.spring.data.couchbase" })
|
||||
@EnableCouchbaseRepositories(basePackages = { "com.baeldung.spring.data.couchbase" })
|
||||
public class MyCouchbaseConfig extends AbstractCouchbaseConfiguration {
|
||||
|
||||
public static final List<String> NODE_LIST = Arrays.asList("localhost");
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase;
|
||||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import org.springframework.data.couchbase.core.query.Consistency;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -7,9 +7,9 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.IntegrationTest;
|
||||
import org.baeldung.spring.data.couchbase.MyCouchbaseConfig;
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase.IntegrationTest;
|
||||
import com.baeldung.spring.data.couchbase.MyCouchbaseConfig;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -9,9 +9,9 @@ import java.util.List;
|
|||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.IntegrationTest;
|
||||
import org.baeldung.spring.data.couchbase.MyCouchbaseConfig;
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase.IntegrationTest;
|
||||
import com.baeldung.spring.data.couchbase.MyCouchbaseConfig;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase.service;
|
||||
package com.baeldung.spring.data.couchbase.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@ -1,9 +1,9 @@
|
|||
package org.baeldung.spring.data.couchbase2b;
|
||||
package com.baeldung.spring.data.couchbase2b;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Campus;
|
||||
import com.baeldung.spring.data.couchbase.model.Campus;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
|
@ -17,7 +17,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
|||
import com.couchbase.client.java.Bucket;
|
||||
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories(basePackages = { "org.baeldung.spring.data.couchbase2b" })
|
||||
@EnableCouchbaseRepositories(basePackages = { "com.baeldung.spring.data.couchbase2b" })
|
||||
public class MultiBucketCouchbaseConfig extends AbstractCouchbaseConfiguration {
|
||||
|
||||
public static final List<String> NODE_LIST = Arrays.asList("localhost");
|
|
@ -1,10 +1,10 @@
|
|||
package org.baeldung.spring.data.couchbase2b;
|
||||
package com.baeldung.spring.data.couchbase2b;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = { "org.baeldung.spring.data.couchbase2b" })
|
||||
@ComponentScan(basePackages = { "com.baeldung.spring.data.couchbase2b" })
|
||||
public class MultiBucketIntegrationTestConfig {
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase2b;
|
||||
package com.baeldung.spring.data.couchbase2b;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -9,9 +9,9 @@ import java.util.Set;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Campus;
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketLiveTest;
|
||||
import org.baeldung.spring.data.couchbase2b.repos.CampusRepository;
|
||||
import com.baeldung.spring.data.couchbase.model.Campus;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketLiveTest;
|
||||
import com.baeldung.spring.data.couchbase2b.repos.CampusRepository;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.geo.Distance;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -7,9 +7,9 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Person;
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketLiveTest;
|
||||
import com.baeldung.spring.data.couchbase.model.Person;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketLiveTest;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.spring.data.couchbase2b.service;
|
||||
package com.baeldung.spring.data.couchbase2b.service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -9,9 +9,9 @@ import java.util.List;
|
|||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.baeldung.spring.data.couchbase.model.Student;
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
|
||||
import org.baeldung.spring.data.couchbase2b.MultiBucketLiveTest;
|
||||
import com.baeldung.spring.data.couchbase.model.Student;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketCouchbaseConfig;
|
||||
import com.baeldung.spring.data.couchbase2b.MultiBucketLiveTest;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
|
@ -4,5 +4,5 @@ This module contains articles about Spring Data with EclipseLink.
|
|||
|
||||
### Relevant articles
|
||||
|
||||
- [A Guide to EclipseLink with Spring](http://www.baeldung.com/spring-eclipselink)
|
||||
- [A Guide to EclipseLink with Spring](https://www.baeldung.com/spring-eclipselink)
|
||||
- [Pessimistic Locking in JPA](https://www.baeldung.com/jpa-pessimistic-locking)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,11 +1,11 @@
|
|||
## Spring Data Elasticsearch
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Spring Data Elasticsearch](http://www.baeldung.com/spring-data-elasticsearch-tutorial)
|
||||
- [Elasticsearch Queries with Spring Data](http://www.baeldung.com/spring-data-elasticsearch-queries)
|
||||
- [Guide to Elasticsearch in Java](http://www.baeldung.com/elasticsearch-java)
|
||||
- [Geospatial Support in ElasticSearch](http://www.baeldung.com/elasticsearch-geo-spatial)
|
||||
- [A Simple Tagging Implementation with Elasticsearch](http://www.baeldung.com/elasticsearch-tagging)
|
||||
- [Introduction to Spring Data Elasticsearch](https://www.baeldung.com/spring-data-elasticsearch-tutorial)
|
||||
- [Elasticsearch Queries with Spring Data](https://www.baeldung.com/spring-data-elasticsearch-queries)
|
||||
- [Guide to Elasticsearch in Java](https://www.baeldung.com/elasticsearch-java)
|
||||
- [Geospatial Support in ElasticSearch](https://www.baeldung.com/elasticsearch-geo-spatial)
|
||||
- [A Simple Tagging Implementation with Elasticsearch](https://www.baeldung.com/elasticsearch-tagging)
|
||||
|
||||
### Build the Project with Tests Running
|
||||
```
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,3 +1,3 @@
|
|||
### Relevant articles
|
||||
|
||||
- [A Guide to GemFire with Spring Data](http://www.baeldung.com/spring-data-gemfire)
|
||||
- [A Guide to GemFire with Spring Data](https://www.baeldung.com/spring-data-gemfire)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -3,4 +3,4 @@
|
|||
This module contains articles about Spring Data Key-Value
|
||||
|
||||
### Relevant Articles:
|
||||
- [A Guide to Spring Data Key Value](http://www.baeldung.com/spring-data-key-value)
|
||||
- [A Guide to Spring Data Key Value](https://www.baeldung.com/spring-data-key-value)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,8 +1,8 @@
|
|||
## Spring Data Neo4j
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Spring Data Neo4j](http://www.baeldung.com/spring-data-neo4j-intro)
|
||||
- [A Guide to Neo4J with Java](http://www.baeldung.com/java-neo4j)
|
||||
- [Introduction to Spring Data Neo4j](https://www.baeldung.com/spring-data-neo4j-intro)
|
||||
- [A Guide to Neo4J with Java](https://www.baeldung.com/java-neo4j)
|
||||
|
||||
### Build the Project with Tests Running
|
||||
```
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,8 +1,8 @@
|
|||
## Spring Data Redis
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Spring Data Redis](http://www.baeldung.com/spring-data-redis-tutorial)
|
||||
- [PubSub Messaging with Spring Data Redis](http://www.baeldung.com/spring-data-redis-pub-sub)
|
||||
- [Introduction to Spring Data Redis](https://www.baeldung.com/spring-data-redis-tutorial)
|
||||
- [PubSub Messaging with Spring Data Redis](https://www.baeldung.com/spring-data-redis-pub-sub)
|
||||
- [An Introduction to Spring Data Redis Reactive](https://www.baeldung.com/spring-data-redis-reactive)
|
||||
|
||||
### Build the Project with Tests Running
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -3,4 +3,4 @@
|
|||
This module contains articles about Spring Data with Solr.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Spring Data Solr](http://www.baeldung.com/spring-data-solr)
|
||||
- [Introduction to Spring Data Solr](https://www.baeldung.com/spring-data-solr)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung;
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -49,8 +49,8 @@ public class ResponseLogFilter extends ZuulFilter {
|
|||
|
||||
context.setResponseBody(responseData);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
catch (Exception e) {
|
||||
logger.error("error occurred at response log filter", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -1,72 +1,88 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-core-3</artifactId>
|
||||
<name>spring-core-3</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-spring-5</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-spring-5</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>${annotation-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven.surefire.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.surefire.version>2.22.1</maven.surefire.version>
|
||||
<annotation-api.version>1.3.2</annotation-api.version>
|
||||
</properties>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-core-3</artifactId>
|
||||
<name>spring-core-3</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-spring-5</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-spring-5</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>${annotation-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven.surefire.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.surefire.version>2.22.1</maven.surefire.version>
|
||||
<annotation-api.version>1.3.2</annotation-api.version>
|
||||
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class Application {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static void main(String[] args) {
|
||||
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
||||
|
||||
Foo foo = context.getBean(Foo.class);
|
||||
Bar bar = context.getBean(Bar.class, "Some name");
|
||||
|
||||
System.out.println(foo);
|
||||
System.out.println("Bar's name: " + bar.getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = ApplicationConfig.class)
|
||||
public class ApplicationConfig {
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class Bar {
|
||||
|
||||
private String name;
|
||||
|
||||
public Bar(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Foo {
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.baeldung.spring.patterns.proxy;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.spring.patterns.proxy;
|
||||
|
||||
public class Book {
|
||||
|
||||
private String author;
|
||||
|
||||
public Book(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.spring.patterns.proxy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class BookController {
|
||||
|
||||
@Autowired
|
||||
private BookManager manager;
|
||||
|
||||
@PostMapping("/book")
|
||||
public Book create(@RequestParam String author) {
|
||||
return manager.create(author);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.spring.patterns.proxy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class BookManager {
|
||||
|
||||
@Autowired
|
||||
private BookRepository repository;
|
||||
|
||||
@Transactional
|
||||
public Book create(String author) {
|
||||
System.out.println(repository.getClass().getName());
|
||||
return repository.create(author);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.spring.patterns.proxy;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class BookRepository {
|
||||
|
||||
public Book create(String author) {
|
||||
return new Book(author);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.baeldung.spring.patterns.singleton;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.baeldung.spring.patterns.singleton;
|
||||
|
||||
public class Book {
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.spring.patterns.singleton;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class BookController {
|
||||
|
||||
@Autowired
|
||||
private BookRepository repository;
|
||||
|
||||
@GetMapping("/book/{id}")
|
||||
public Book findById(@PathVariable long id) {
|
||||
System.out.println(repository);
|
||||
return repository.findById(id).get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.spring.patterns.singleton;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class BookRepository {
|
||||
|
||||
public long count() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Optional<Book> findById(long id) {
|
||||
return Optional.of(new Book());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.spring.patterns.singleton;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class LibraryController {
|
||||
|
||||
@Autowired
|
||||
private BookRepository repository;
|
||||
|
||||
@GetMapping("/count")
|
||||
public Long findCount() {
|
||||
System.out.println(repository);
|
||||
return repository.count();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.baeldung.spring.patterns.template;
|
||||
|
||||
public class Book {
|
||||
|
||||
private long id;
|
||||
private String title;
|
||||
private String author;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.spring.patterns.template;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
public class BookRowMapper implements RowMapper<Book> {
|
||||
|
||||
@Override
|
||||
public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
||||
Book book = new Book();
|
||||
|
||||
book.setId(rs.getLong("id"));
|
||||
book.setTitle(rs.getString("title"));
|
||||
book.setAuthor(rs.getString("author"));
|
||||
|
||||
return book;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class AnnotationConfigApplicationContextUnitTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void whenGetSimpleBean_thenReturnConstructedBean() {
|
||||
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
||||
|
||||
Foo foo = context.getBean(Foo.class);
|
||||
|
||||
assertNotNull(foo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void whenGetPrototypeBean_thenReturnConstructedBean() {
|
||||
|
||||
String expectedName = "Some name";
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
|
||||
|
||||
Bar bar = context.getBean(Bar.class, expectedName);
|
||||
|
||||
assertNotNull(bar);
|
||||
assertThat(bar.getName(), is(expectedName));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = ApplicationConfig.class)
|
||||
public class ApplicationConfig {
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class Bar {
|
||||
|
||||
private String name;
|
||||
|
||||
public Bar(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class ClassPathXmlApplicationContextUnitTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void givenXmlConfiguration_whenGetSimpleBean_thenReturnConstructedBean() {
|
||||
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("patterns-context.xml");
|
||||
|
||||
Foo foo = context.getBean(Foo.class);
|
||||
|
||||
assertNotNull(foo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void givenXmlConfiguration_whenGetPrototypeBean_thenReturnConstructedBean() {
|
||||
|
||||
String expectedName = "Some name";
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("patterns-context.xml");
|
||||
|
||||
Bar bar = context.getBean(Bar.class, expectedName);
|
||||
|
||||
assertNotNull(bar);
|
||||
assertThat(bar.getName(), is(expectedName));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.spring.patterns.factory;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Foo {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="foo" class="com.baeldung.spring.patterns.factory.Foo" />
|
||||
<bean id="bar" scope="prototype" class="com.baeldung.spring.patterns.factory.Bar" />
|
||||
</beans>
|
|
@ -3,9 +3,8 @@ package com.baeldung.cache;
|
|||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -16,28 +15,28 @@ import java.util.concurrent.TimeUnit;
|
|||
@Controller
|
||||
public class CacheControlController {
|
||||
|
||||
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
|
||||
public ResponseEntity<String> helloWorld(@PathVariable String name) {
|
||||
@GetMapping(value = "/hello/{name}")
|
||||
public ResponseEntity<String> hello(@PathVariable String name) {
|
||||
CacheControl cacheControl = CacheControl.maxAge(60, TimeUnit.SECONDS)
|
||||
.noTransform()
|
||||
.mustRevalidate();
|
||||
.noTransform()
|
||||
.mustRevalidate();
|
||||
return ResponseEntity.ok()
|
||||
.cacheControl(cacheControl)
|
||||
.body("Hello " + name);
|
||||
.cacheControl(cacheControl)
|
||||
.body("Hello " + name);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/home/{name}", method = RequestMethod.GET)
|
||||
@GetMapping(value = "/home/{name}")
|
||||
public String home(@PathVariable String name, final HttpServletResponse response) {
|
||||
response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform");
|
||||
return "home";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cache/{name}", method = RequestMethod.GET)
|
||||
@GetMapping(value = "/login/{name}")
|
||||
public ResponseEntity<String> intercept(@PathVariable String name) {
|
||||
return ResponseEntity.ok().body("Hello " + name);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/validate/{name}", method = RequestMethod.GET)
|
||||
@GetMapping(value = "/productInfo/{name}")
|
||||
public ResponseEntity<String> validate(@PathVariable String name, WebRequest request) {
|
||||
|
||||
ZoneId zoneId = ZoneId.of("GMT");
|
||||
|
|
|
@ -35,7 +35,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
WebContentInterceptor interceptor = new WebContentInterceptor();
|
||||
interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS)
|
||||
.noTransform()
|
||||
.mustRevalidate(), "/cache/*");
|
||||
.mustRevalidate(), "/login/*");
|
||||
registry.addInterceptor(interceptor);
|
||||
}
|
||||
}
|
|
@ -37,7 +37,8 @@ public class CacheControlControllerIntegrationTest {
|
|||
this.mockMvc.perform(MockMvcRequestBuilders.get("/hello/baeldung"))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform"));
|
||||
.andExpect(MockMvcResultMatchers.header()
|
||||
.string("Cache-Control","max-age=60, must-revalidate, no-transform"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -59,7 +60,7 @@ public class CacheControlControllerIntegrationTest {
|
|||
|
||||
@Test
|
||||
void whenInterceptor_thenReturnCacheHeader() throws Exception {
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/cache/baeldung"))
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/login/baeldung"))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform"));
|
||||
|
@ -69,7 +70,7 @@ public class CacheControlControllerIntegrationTest {
|
|||
void whenValidate_thenReturnCacheHeader() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(IF_UNMODIFIED_SINCE, "Tue, 04 Feb 2020 19:57:25 GMT");
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/validate/baeldung").headers(headers))
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/productInfo/baeldung").headers(headers))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().is(304));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue