Merge remote-tracking branch 'origin/master'

This commit is contained in:
slavisa-baeldung 2017-04-23 08:18:56 +01:00
commit 64f0428e00
396 changed files with 3598 additions and 1899 deletions

2
.gitignore vendored
View File

@ -31,3 +31,5 @@ spring-openid/src/main/resources/application.properties
.recommenders/ .recommenders/
/spring-hibernate4/nbproject/ /spring-hibernate4/nbproject/
spring-security-openid/src/main/resources/application.properties spring-security-openid/src/main/resources/application.properties
spring-all/*.log

View File

@ -5,3 +5,4 @@
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization) - [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/finite-automata-java) - [Validating Input With Finite Automata in Java](http://www.baeldung.com/finite-automata-java)
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics) - [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers)

View File

@ -3,8 +3,10 @@ package com.baeldung.cxf.aegis;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Test; import org.junit.Test;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -90,4 +92,12 @@ public class BaeldungTest {
xmlReader.close(); xmlReader.close();
return courseRepo; return courseRepo;
} }
@After
public void cleanup(){
File testFile = new File(fileName);
if (testFile.exists()) {
testFile.delete();
}
}
} }

View File

@ -54,6 +54,12 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${httpclient.version}</version> <version>${httpclient.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -24,6 +24,12 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>${spring.version}</version> <version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>

View File

@ -28,11 +28,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- test scoped --> <!-- test scoped -->
@ -78,6 +73,10 @@
<groupId>org.apache.avalon.framework</groupId> <groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-impl</artifactId> <artifactId>avalon-framework-impl</artifactId>
</exclusion> </exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
@ -90,6 +89,12 @@
<groupId>avalon-framework</groupId> <groupId>avalon-framework</groupId>
<artifactId>avalon-framework-impl</artifactId> <artifactId>avalon-framework-impl</artifactId>
<version>${avalon-framework.version}</version> <version>${avalon-framework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -42,6 +42,12 @@
<groupId>org.jxls</groupId> <groupId>org.jxls</groupId>
<artifactId>jxls-jexcel</artifactId> <artifactId>jxls-jexcel</artifactId>
<version>${jexcel.version}</version> <version>${jexcel.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.Before; import org.junit.Before;
import org.junit.After;
public class JExcelTest { public class JExcelTest {
@ -53,4 +54,11 @@ public class JExcelTest {
.get(1)); .get(1));
} }
@After
public void cleanup(){
File testFile = new File(fileLocation);
if (testFile.exists()) {
testFile.delete();
}
}
} }

View File

@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.junit.Before; import org.junit.Before;
import org.junit.After;
public class ExcelTest { public class ExcelTest {
@ -50,4 +51,11 @@ public class ExcelTest {
.get(1)); .get(1));
} }
@After
public void cleanup(){
File testFile = new File(fileLocation);
if (testFile.exists()) {
testFile.delete();
}
}
} }

Binary file not shown.

Binary file not shown.

View File

@ -19,6 +19,12 @@
<groupId>org.apache.thrift</groupId> <groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId> <artifactId>libthrift</artifactId>
<version>${thrift.version}</version> <version>${thrift.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -55,6 +55,12 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${org.apache.httpcomponents.version}</version> <version>${org.apache.httpcomponents.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -19,12 +19,24 @@
<groupId>com.amazonaws</groupId> <groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId> <artifactId>aws-lambda-java-core</artifactId>
<version>${aws-lambda-java-core.version}</version> <version>${aws-lambda-java-core.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.amazonaws</groupId> <groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId> <artifactId>aws-lambda-java-events</artifactId>
<version>${aws-lambda-java-events.version}</version> <version>${aws-lambda-java-events.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -12,6 +12,12 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId> <artifactId>spring-core</artifactId>
<version>${spring.version}</version> <version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>

View File

@ -12,3 +12,4 @@
- [Spring Security Redirect to the Previous URL After Login](http://www.baeldung.com/spring-security-redirect-login) - [Spring Security Redirect to the Previous URL After Login](http://www.baeldung.com/spring-security-redirect-login)
- [Java 9 Process API Improvements](http://www.baeldung.com/java-9-process-api) - [Java 9 Process API Improvements](http://www.baeldung.com/java-9-process-api)
- [Introduction to Java 9 StackWalking API](http://www.baeldung.com/java-9-stackwalking-api) - [Introduction to Java 9 StackWalking API](http://www.baeldung.com/java-9-stackwalking-api)
- [Introduction to Project Jigsaw](http://www.baeldung.com/project-jigsaw-java-modularity)

View File

@ -92,3 +92,9 @@
- [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list) - [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list)
- [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list) - [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list)
- [An Introduction to ThreadLocal in Java](http://www.baeldung.com/java-threadlocal) - [An Introduction to ThreadLocal in Java](http://www.baeldung.com/java-threadlocal)
- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow)
- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum)
- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections)
- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer)
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
- [Guide to sun.misc.Unsafe](http://www.baeldung.com/java-unsafe)

View File

@ -92,11 +92,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@ -176,6 +171,12 @@
<groupId>org.owasp.esapi</groupId> <groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId> <artifactId>esapi</artifactId>
<version>2.1.0.1</version> <version>2.1.0.1</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -0,0 +1,36 @@
package com.baeldung.transferqueue;
import java.util.concurrent.TransferQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class Consumer implements Runnable {
private final TransferQueue<String> transferQueue;
private final String name;
private final int numberOfMessagesToConsume;
public final AtomicInteger numberOfConsumedMessages = new AtomicInteger();
public Consumer(TransferQueue<String> transferQueue, String name, int numberOfMessagesToConsume) {
this.transferQueue = transferQueue;
this.name = name;
this.numberOfMessagesToConsume = numberOfMessagesToConsume;
}
@Override
public void run() {
for (int i = 0; i < numberOfMessagesToConsume; i++) {
try {
System.out.println("Consumer: " + name + " is waiting to take element...");
String element = transferQueue.take();
longProcessing(element);
System.out.println("Consumer: " + name + " received element: " + element);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void longProcessing(String element) throws InterruptedException {
numberOfConsumedMessages.incrementAndGet();
Thread.sleep(500);
}
}

View File

@ -0,0 +1,36 @@
package com.baeldung.transferqueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TransferQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class Producer implements Runnable {
private final TransferQueue<String> transferQueue;
private final String name;
private final Integer numberOfMessagesToProduce;
public final AtomicInteger numberOfProducedMessages = new AtomicInteger();
public Producer(TransferQueue<String> transferQueue, String name, Integer numberOfMessagesToProduce) {
this.transferQueue = transferQueue;
this.name = name;
this.numberOfMessagesToProduce = numberOfMessagesToProduce;
}
@Override
public void run() {
for (int i = 0; i < numberOfMessagesToProduce; i++) {
try {
System.out.println("Producer: " + name + " is waiting to transfer...");
boolean added = transferQueue.tryTransfer("A" + i, 4000, TimeUnit.MILLISECONDS);
if (!added) {
System.out.println("can not add an element due to the timeout");
} else {
numberOfProducedMessages.incrementAndGet();
System.out.println("Producer: " + name + " transferred element: A" + i);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

View File

@ -0,0 +1,83 @@
package com.baeldung.synchronousqueue;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import static junit.framework.TestCase.assertEquals;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SynchronousQueueTest {
@Test
public void givenTwoThreads_whenWantToExchangeUsingLockGuardedVariable_thenItSucceed() throws InterruptedException {
//given
ExecutorService executor = Executors.newFixedThreadPool(2);
AtomicInteger sharedState = new AtomicInteger();
CountDownLatch countDownLatch = new CountDownLatch(1);
Runnable producer = () -> {
Integer producedElement = ThreadLocalRandom.current().nextInt();
System.out.println("Saving an element: " + producedElement + " to the exchange point");
sharedState.set(producedElement);
countDownLatch.countDown();
};
Runnable consumer = () -> {
try {
countDownLatch.await();
Integer consumedElement = sharedState.get();
System.out.println("consumed an element: " + consumedElement + " from the exchange point");
} catch (InterruptedException ex) {
ex.printStackTrace();
}
};
//when
executor.execute(producer);
executor.execute(consumer);
//then
executor.awaitTermination(500, TimeUnit.MILLISECONDS);
executor.shutdown();
assertEquals(countDownLatch.getCount(), 0);
}
@Test
public void givenTwoThreads_whenWantToExchangeUsingSynchronousQueue_thenItSucceed() throws InterruptedException {
//given
ExecutorService executor = Executors.newFixedThreadPool(2);
final SynchronousQueue<Integer> queue = new SynchronousQueue<>();
Runnable producer = () -> {
Integer producedElement = ThreadLocalRandom.current().nextInt();
try {
System.out.println("Saving an element: " + producedElement + " to the exchange point");
queue.put(producedElement);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
};
Runnable consumer = () -> {
try {
Integer consumedElement = queue.take();
System.out.println("consumed an element: " + consumedElement + " from the exchange point");
} catch (InterruptedException ex) {
ex.printStackTrace();
}
};
//when
executor.execute(producer);
executor.execute(consumer);
//then
executor.awaitTermination(500, TimeUnit.MILLISECONDS);
executor.shutdown();
assertEquals(queue.size(), 0);
}
}

View File

@ -0,0 +1,74 @@
package com.baeldung.transferqueue;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.util.concurrent.*;
import static junit.framework.TestCase.assertEquals;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TransferQueueTest {
@Test
public void givenTransferQueue_whenUseMultipleConsumersAndMultipleProducers_thenShouldProcessAllMessages() throws InterruptedException {
//given
TransferQueue<String> transferQueue = new LinkedTransferQueue<>();
ExecutorService exService = Executors.newFixedThreadPool(3);
Producer producer1 = new Producer(transferQueue, "1", 3);
Producer producer2 = new Producer(transferQueue, "2", 3);
Consumer consumer1 = new Consumer(transferQueue, "1", 3);
Consumer consumer2 = new Consumer(transferQueue, "2", 3);
//when
exService.execute(producer1);
exService.execute(producer2);
exService.execute(consumer1);
exService.execute(consumer2);
//then
exService.awaitTermination(10_000, TimeUnit.MILLISECONDS);
exService.shutdown();
assertEquals(producer1.numberOfProducedMessages.intValue(), 3);
assertEquals(producer2.numberOfProducedMessages.intValue(), 3);
}
@Test
public void givenTransferQueue_whenUseOneConsumerAndOneProducer_thenShouldProcessAllMessages() throws InterruptedException {
//given
TransferQueue<String> transferQueue = new LinkedTransferQueue<>();
ExecutorService exService = Executors.newFixedThreadPool(2);
Producer producer = new Producer(transferQueue, "1", 3);
Consumer consumer = new Consumer(transferQueue, "1", 3);
//when
exService.execute(producer);
exService.execute(consumer);
//then
exService.awaitTermination(5000, TimeUnit.MILLISECONDS);
exService.shutdown();
assertEquals(producer.numberOfProducedMessages.intValue(), 3);
assertEquals(consumer.numberOfConsumedMessages.intValue(), 3);
}
@Test
public void givenTransferQueue_whenUseOneProducerAndNoConsumers_thenShouldFailWithTimeout() throws InterruptedException {
//given
TransferQueue<String> transferQueue = new LinkedTransferQueue<>();
ExecutorService exService = Executors.newFixedThreadPool(2);
Producer producer = new Producer(transferQueue, "1", 3);
//when
exService.execute(producer);
//then
exService.awaitTermination(5000, TimeUnit.MILLISECONDS);
exService.shutdown();
assertEquals(producer.numberOfProducedMessages.intValue(), 0);
}
}

View File

@ -6,12 +6,14 @@ import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.Test; import org.junit.Test;
public class FileNotFoundExceptionUnitTest { public class FileNotFoundExceptionUnitTest {
private static final Logger LOG = Logger.getLogger(FileNotFoundExceptionUnitTest.class); private static final Logger LOG = LoggerFactory.getLogger(FileNotFoundExceptionUnitTest.class);
private String fileName = Double.toString(Math.random()); private String fileName = Double.toString(Math.random());

View File

@ -22,11 +22,23 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version> <version>${spring-framework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId> <artifactId>spring-context-support</artifactId>
<version>${spring-framework.version}</version> <version>${spring-framework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- Logging with SLF4J & LogBack --> <!-- Logging with SLF4J & LogBack -->
@ -46,11 +58,6 @@
<artifactId>jcl-over-slf4j</artifactId> <artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- Test-Scoped Dependencies --> <!-- Test-Scoped Dependencies -->
<dependency> <dependency>

3
cucumber/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant articles
- [Cucumber and Scenario Outline](http://www.baeldung.com/cucumber-scenario-outline)

View File

@ -201,12 +201,6 @@
<artifactId>querydsl-jpa</artifactId> <artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version> <version>${querydsl.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -40,11 +40,6 @@
<artifactId>jcl-over-slf4j</artifactId> <artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- test scoped --> <!-- test scoped -->

View File

@ -18,7 +18,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<feign.version>9.4.0</feign.version> <feign.version>9.4.0</feign.version>
<slf4j.version>1.7.21</slf4j.version> <slf4j.version>1.7.21</slf4j.version>
<log4j.version>2.7</log4j.version>
<lombok.version>1.16.12</lombok.version> <lombok.version>1.16.12</lombok.version>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
@ -52,16 +51,6 @@
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version> <version>${slf4j.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36}:%n[+] %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

3
groovy-spock/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant articles
- [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock)

View File

@ -76,11 +76,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency> <dependency>

View File

@ -1 +1,2 @@
## Relevant articles: ### Relevant articles:
- [New Stream, Comparator and Collector Functionality in Guava 21](http://www.baeldung.com/guava-21-new)

View File

@ -155,11 +155,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
</dependencies> </dependencies>

View File

@ -28,6 +28,12 @@
<groupId>org.apache.hbase</groupId> <groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId> <artifactId>hbase-client</artifactId>
<version>${hbase.version}</version> <version>${hbase.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.hbase</groupId> <groupId>org.apache.hbase</groupId>

62
hibernate5/pom.xml Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.baeldung</groupId>
<artifactId>hibernate5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hibernate5</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Maven plugins -->
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.194</version>
</dependency>
</dependencies>
<build>
<finalName>hibernate5</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,30 @@
package com.baeldung.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import com.baeldung.hibernate.pojo.Supplier;
/**
* Hello world!
*
*/
public class App {
public static void main(String[] args) {
try {
// NOTE: this is just for boostrap testing for multitenancy.
System.out.println("Checking the system.");
SessionFactory sessionFactory = HibernateMultiTenantUtil.getSessionFactory();
Session currentSession = sessionFactory.withOptions().tenantIdentifier("h2db1").openSession();
Transaction transaction = currentSession.getTransaction();
transaction.begin();
currentSession.createCriteria(Supplier.class).list().stream().forEach(System.out::println);
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,41 @@
package com.baeldung.hibernate;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
public class ConfigurableMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider {
private final Map<String, ConnectionProvider> connectionProviderMap =
new HashMap<>();
public ConfigurableMultiTenantConnectionProvider(
Map<String, ConnectionProvider> connectionProviderMap) {
this.connectionProviderMap.putAll( connectionProviderMap );
}
@Override
protected ConnectionProvider getAnyConnectionProvider() {
System.out.println("Any");
return connectionProviderMap.values().iterator().next();
}
@Override
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
System.out.println("Specific");
return connectionProviderMap.get( tenantIdentifier );
}
@Override
public Connection getConnection(String tenantIdentifier) throws SQLException {
Connection connection = super.getConnection(tenantIdentifier);
// uncomment to see option 2 for SCHEMA strategy.
//connection.createStatement().execute("SET SCHEMA '" + tenantIdentifier + "'");
return connection;
}
}

View File

@ -0,0 +1,95 @@
package com.baeldung.hibernate;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.ServiceRegistry;
import com.baeldung.hibernate.pojo.Supplier;
public class HibernateMultiTenantUtil {
private static SessionFactory sessionFactory;
private static Map<String, ConnectionProvider> connectionProviderMap = new HashMap<>();
private static final String[] tenantDBNames = { "mydb1","mydb2"};
public static SessionFactory getSessionFactory() throws UnsupportedTenancyException {
if (sessionFactory == null) {
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = configureServiceRegistry(configuration);
sessionFactory = makeSessionFactory (serviceRegistry);
// sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}
private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) {
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
for(Class annotatedClasses : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass( annotatedClasses );
}
Metadata metadata = metadataSources.buildMetadata();
return metadata.getSessionFactoryBuilder().build();
}
private static Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Supplier.class
};
}
private static ServiceRegistry configureServiceRegistry(Configuration configuration) throws UnsupportedTenancyException {
Properties properties = configuration.getProperties();
connectionProviderMap = setUpConnectionProviders(properties, tenantDBNames);
properties.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, new ConfigurableMultiTenantConnectionProvider(connectionProviderMap));
return new StandardServiceRegistryBuilder().applySettings(properties).build();
}
private static Map<String, ConnectionProvider> setUpConnectionProviders(Properties properties, String[] tenantNames) throws UnsupportedTenancyException {
Map<String, ConnectionProvider> providerMap = new HashMap<>();
for (String tenant : tenantNames) {
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
String tenantStrategy = properties.getProperty("hibernate.multiTenancy");
System.out.println("Strategy:"+tenantStrategy);
properties.put(Environment.URL, tenantUrl(properties.getProperty(Environment.URL), tenant, tenantStrategy));
System.out.println("URL:"+properties.getProperty(Environment.URL));
connectionProvider.configure(properties);
System.out.println("Tenant:"+tenant);
providerMap.put(tenant, connectionProvider);
}
System.out.println("Added connections for:");
providerMap.keySet().stream().forEach(System.out::println);
return providerMap;
}
private static Object tenantUrl(String originalUrl, String tenant, String tenantStrategy) throws UnsupportedTenancyException {
if (tenantStrategy.toUpperCase().equals("DATABASE")) {
return originalUrl.replace(DEFAULT_DB_NAME, tenant);
} else if (tenantStrategy.toUpperCase().equals("SCHEMA")) {
return originalUrl + String.format(SCHEMA_TOKEN, tenant);
} else {
throw new UnsupportedTenancyException("Not yet supported");
}
}
public static final String SCHEMA_TOKEN = ";INIT=CREATE SCHEMA IF NOT EXISTS %1$s\\;SET SCHEMA %1$s";
public static final String DEFAULT_DB_NAME = "mydb1";
}

View File

@ -0,0 +1,24 @@
package com.baeldung.hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
Configuration configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.hibernate;
public class UnsupportedTenancyException extends Exception {
public UnsupportedTenancyException (String message) {
super(message);
}
}

View File

@ -0,0 +1,67 @@
package com.baeldung.hibernate.pojo;
// Generated Feb 9, 2017 11:31:36 AM by Hibernate Tools 5.1.0.Final
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.junit.runners.Suite.SuiteClasses;
/**
* Suppliers generated by hbm2java
*/
@Entity(name = "Supplier")
@Table(name ="Supplier")
public class Supplier implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String country;
public Supplier() {
}
public Supplier(String name, String country) {
this.name = name;
this.country = country;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
@Override
public String toString() {
return new StringBuffer().append("[").append(id).append(",").append(name).append(",").append(country).append("]").toString();
}
@Override
public boolean equals(Object obj) {
return name.equals(((Supplier) obj).getName());
}
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1</property>
<property name="hibernate.connection.username">sa</property>
<property name="connection.password"/>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.multiTenancy">DATABASE</property>
</session-factory>
</hibernate-configuration>

View File

@ -0,0 +1,73 @@
package com.baeldung.hibernate;
import static org.junit.Assert.assertNotEquals;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.Before;
import org.junit.Test;
import com.baeldung.hibernate.pojo.Supplier;
public class MultiTenantHibernateTest {
@Test
public void givenDBMode_whenFetchingSuppliers_thenComparingFromDbs () {
SessionFactory sessionFactory;
try {
sessionFactory = HibernateMultiTenantUtil.getSessionFactory();
Session db1Session = sessionFactory
.withOptions().tenantIdentifier("mydb1").openSession();
initDb1(db1Session);
Transaction transaction = db1Session.getTransaction();
transaction.begin();
Supplier supplierFromDB1 = (Supplier)db1Session.createCriteria(Supplier.class).list().get(0);
transaction.commit();
Session db2Session = sessionFactory
.withOptions().tenantIdentifier("mydb2").openSession();
initDb2(db2Session);
db2Session.getTransaction().begin();
Supplier supplierFromDB2 = (Supplier) db2Session.createCriteria(Supplier.class).list().get(0);
db2Session.getTransaction().commit();
System.out.println(supplierFromDB1);
System.out.println(supplierFromDB2);
assertNotEquals(supplierFromDB1, supplierFromDB2);
} catch (UnsupportedTenancyException e) {
e.printStackTrace();
}
}
private void initDb1(Session db1Session) {
System.out.println("Init DB1");
Transaction transaction = db1Session.getTransaction();
transaction.begin();
db1Session.createSQLQuery("DROP ALL OBJECTS").executeUpdate();
db1Session.createSQLQuery("create table Supplier (id integer generated by default as identity, country varchar(255), name varchar(255), primary key (id))").executeUpdate();
db1Session.createSQLQuery("insert into Supplier (id, country, name) values (null, 'John', 'USA')").executeUpdate();
transaction.commit();
}
private void initDb2(Session db2Session) {
System.out.println("Init DB2");
Transaction transaction = db2Session.getTransaction();
transaction.begin();
db2Session.createSQLQuery("DROP ALL OBJECTS").executeUpdate();
db2Session.createSQLQuery("create table Supplier (id integer generated by default as identity, country varchar(255), name varchar(255), primary key (id))").executeUpdate();
db2Session.createSQLQuery("insert into Supplier (id, country, name) values (null, 'Miller', 'UK')").executeUpdate();
transaction.commit();
}
}

View File

@ -41,6 +41,12 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId> <artifactId>fluent-hc</artifactId>
<version>${httpclient.version}</version> <version>${httpclient.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
@ -59,6 +65,12 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId> <artifactId>httpasyncclient</artifactId>
<version>${httpasyncclient.version}</version> <!-- 4.0.2 --> <!-- 4.1-beta1 --> <version>${httpasyncclient.version}</version> <!-- 4.0.2 --> <!-- 4.1-beta1 -->
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- logging --> <!-- logging -->
@ -80,11 +92,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- test scoped --> <!-- test scoped -->

View File

@ -56,6 +56,12 @@
<groupId>com.netflix.hystrix</groupId> <groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId> <artifactId>hystrix-core</artifactId>
<version>${hystrix-core.version}</version> <version>${hystrix-core.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.netflix.hystrix</groupId> <groupId>com.netflix.hystrix</groupId>

View File

@ -17,11 +17,23 @@
<groupId>net.imagej</groupId> <groupId>net.imagej</groupId>
<artifactId>ij</artifactId> <artifactId>ij</artifactId>
<version>${ij.version}</version> <version>${ij.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.openimaj</groupId> <groupId>org.openimaj</groupId>
<artifactId>core-image</artifactId> <artifactId>core-image</artifactId>
<version>${core-image.version}</version> <version>${core-image.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -27,3 +27,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat) - [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat)
- [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional) - [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional)
- [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map) - [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map)
- [Jackson Streaming API](http://www.baeldung.com/jackson-streaming-api)

View File

@ -154,11 +154,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
</dependencies> </dependencies>

View File

@ -49,11 +49,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

View File

@ -2,3 +2,4 @@
- [Introduction to Javaslang](http://www.baeldung.com/javaslang) - [Introduction to Javaslang](http://www.baeldung.com/javaslang)
- [Guide to Try in Javaslang](http://www.baeldung.com/javaslang-try) - [Guide to Try in Javaslang](http://www.baeldung.com/javaslang-try)
- [Guide to Pattern Matching in Javaslang](http://www.baeldung.com/javaslang-pattern-matching) - [Guide to Pattern Matching in Javaslang](http://www.baeldung.com/javaslang-pattern-matching)
- [Property Testing Example With Javaslang](http://www.baeldung.com/javaslang-property-testing)

View File

@ -49,6 +49,12 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${org.apache.httpcomponents.version}</version> <version>${org.apache.httpcomponents.version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -135,6 +135,9 @@
</sources> </sources>
<outputDirectory>${basedir}/src/main/java</outputDirectory> <outputDirectory>${basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir> <clearOutputDir>false</clearOutputDir>
<noGeneratedHeaderComments>true</noGeneratedHeaderComments>
<extension>true</extension>
<generateEpisode>false</generateEpisode>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -0,0 +1,48 @@
package com.baeldung.jaxb.gen;
import javax.xml.bind.annotation.XmlRegistry;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.baeldung.jaxb.gen package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.jaxb.gen
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link UserRequest }
*
*/
public UserRequest createUserRequest() {
return new UserRequest();
}
/**
* Create an instance of {@link UserResponse }
*
*/
public UserResponse createUserResponse() {
return new UserResponse();
}
}

View File

@ -0,0 +1,87 @@
package com.baeldung.jaxb.gen;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for UserRequest complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="UserRequest"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserRequest", propOrder = {
"id",
"name"
})
@XmlRootElement(name = "userRequest")
public class UserRequest
implements Serializable
{
private final static long serialVersionUID = -1L;
protected int id;
@XmlElement(required = true)
protected String name;
/**
* Gets the value of the id property.
*
*/
public int getId() {
return id;
}
/**
* Sets the value of the id property.
*
*/
public void setId(int value) {
this.id = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
}

View File

@ -0,0 +1,149 @@
package com.baeldung.jaxb.gen;
import java.io.Serializable;
import java.util.Calendar;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.w3._2001.xmlschema.Adapter1;
/**
* <p>Java class for UserResponse complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="UserResponse"&gt;
* &lt;complexContent&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
* &lt;sequence&gt;
* &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/&gt;
* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="gender" type="{http://www.w3.org/2001/XMLSchema}string"/&gt;
* &lt;element name="created" type="{http://www.w3.org/2001/XMLSchema}dateTime"/&gt;
* &lt;/sequence&gt;
* &lt;/restriction&gt;
* &lt;/complexContent&gt;
* &lt;/complexType&gt;
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserResponse", propOrder = {
"id",
"name",
"gender",
"created"
})
@XmlRootElement(name = "userResponse")
public class UserResponse
implements Serializable
{
private final static long serialVersionUID = -1L;
protected int id;
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String gender;
@XmlElement(required = true, type = String.class)
@XmlJavaTypeAdapter(Adapter1 .class)
@XmlSchemaType(name = "dateTime")
protected Calendar created;
/**
* Gets the value of the id property.
*
*/
public int getId() {
return id;
}
/**
* Sets the value of the id property.
*
*/
public void setId(int value) {
this.id = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the gender property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getGender() {
return gender;
}
/**
* Sets the value of the gender property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setGender(String value) {
this.gender = value;
}
/**
* Gets the value of the created property.
*
* @return
* possible object is
* {@link String }
*
*/
public Calendar getCreated() {
return created;
}
/**
* Sets the value of the created property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCreated(Calendar value) {
this.created = value;
}
}

View File

@ -0,0 +1,2 @@
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.baeldung.com/jaxb/gen", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.baeldung.jaxb.gen;

View File

@ -0,0 +1,23 @@
package org.w3._2001.xmlschema;
import java.util.Calendar;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class Adapter1
extends XmlAdapter<String, Calendar>
{
public Calendar unmarshal(String value) {
return (javax.xml.bind.DatatypeConverter.parseDateTime(value));
}
public String marshal(Calendar value) {
if (value == null) {
return null;
}
return (javax.xml.bind.DatatypeConverter.printDateTime(value));
}
}

View File

@ -1,3 +1,4 @@
### Relevant Articles: ### Relevant Articles:
- [Scheduling in Java EE](http://www.baeldung.com/scheduling-in-java-enterprise-edition) - [Scheduling in Java EE](http://www.baeldung.com/scheduling-in-java-enterprise-edition)
- [JSON Processing in Java EE 7](http://www.baeldung.com/jee7-json) - [JSON Processing in Java EE 7](http://www.baeldung.com/jee7-json)
- [Converters, Listeners and Validators in Java EE 7](http://www.baeldung.com/java-ee7-converter-listener-validator)

View File

@ -1,3 +1,8 @@
### Relevant articles
- [Intro to JHipster](http://www.baeldung.com/jhipster)
# baeldung # baeldung
This application was generated using JHipster 4.0.8, you can find documentation and help at [https://jhipster.github.io/documentation-archive/v4.0.8](https://jhipster.github.io/documentation-archive/v4.0.8). This application was generated using JHipster 4.0.8, you can find documentation and help at [https://jhipster.github.io/documentation-archive/v4.0.8](https://jhipster.github.io/documentation-archive/v4.0.8).

View File

@ -65,6 +65,12 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version> <version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
@ -92,11 +98,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -11,6 +11,12 @@
<groupId>org.everit.json</groupId> <groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema</artifactId> <artifactId>org.everit.json.schema</artifactId>
<version>${everit.json.schema.version}</version> <version>${everit.json.schema.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

3
jws/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant articles
- [A Guide to the Java Web Start](http://www.baeldung.com/java-web-start)

View File

@ -1,3 +1,10 @@
### Relevant articles
- [Guide to Reactive Microservices Using Lagom Framework](http://www.baeldung.com/lagom-reactive-microservices)
Steps to setup from scratch Steps to setup from scratch
1) Create sbt build file "build.sbt" 1) Create sbt build file "build.sbt"

View File

@ -7,6 +7,8 @@
- [Introduction to Javassist](http://www.baeldung.com/javassist) - [Introduction to Javassist](http://www.baeldung.com/javassist)
- [Embedded Jetty Server in Java](http://www.baeldung.com/jetty-embedded) - [Embedded Jetty Server in Java](http://www.baeldung.com/jetty-embedded)
- [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink) - [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink)
- [Introduction to JSONassert](http://www.baeldung.com/jsonassert)
- [Intro to JaVer](http://www.baeldung.com/javers)
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. 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

@ -111,6 +111,12 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${httpclient.version}</version> <version>${httpclient.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
@ -141,11 +147,23 @@
<groupId>org.apache.flink</groupId> <groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId> <artifactId>flink-core</artifactId>
<version>${flink.version}</version> <version>${flink.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.flink</groupId> <groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId> <artifactId>flink-java</artifactId>
<version>${flink.version}</version> <version>${flink.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.flink</groupId> <groupId>org.apache.flink</groupId>
@ -153,6 +171,11 @@
<version>${flink.version}</version> <version>${flink.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies> </dependencies>
<properties> <properties>

View File

@ -1,7 +1,6 @@
package com.baeldung.commons.math; package com.baeldung.commons.math;
import org.apache.commons.math3.fraction.Fraction; import org.apache.commons.math3.fraction.Fraction;
import org.apache.commons.math3.fraction.FractionFormat;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@ -32,6 +32,12 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>${springframework.version}</version> <version>${springframework.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>

16
mybatis/.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
*.class
.settings
.project
*.log
#folders#
/target
/src/main/webapp/WEB-INF/classes
*/META-INF/*
/testdb1
# Packaged files #
*.jar
*.war
*.ear

View File

@ -3,7 +3,6 @@ package com.baeldung.mybatis.utils;
import com.baeldung.mybatis.mapper.AddressMapper; import com.baeldung.mybatis.mapper.AddressMapper;
import com.baeldung.mybatis.mapper.PersonMapper; import com.baeldung.mybatis.mapper.PersonMapper;
import org.apache.ibatis.datasource.pooled.PooledDataSource; import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.SQL; import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.Configuration;
@ -12,8 +11,6 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
public class MyBatisUtil { public class MyBatisUtil {
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";

View File

@ -1,145 +0,0 @@
package com.baeldung.mybatis.mapper;
import com.baeldung.mybatis.model.Address;
import com.baeldung.mybatis.model.Person;
import com.baeldung.mybatis.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import static junit.framework.TestCase.assertEquals;
public class PersonMapperTest {
SqlSession session;
@Before
public void setup() throws SQLException {
session = MyBatisUtil.buildqlSessionFactory().openSession();
createTables(session);
}
private void createTables(SqlSession session) throws SQLException {
String createPersonTable = "create table person (" + "personId integer not null generated always as"
+ " identity (start with 1, increment by 1), " + "name varchar(30) not null, "
+ "constraint primary_key_person primary key (personId))";
String createAddressTable = "create table address (" + "addressId integer not null generated always as"
+ " identity (start with 1, increment by 1), " + "streetAddress varchar(300), personId integer, "
+ "constraint primary_key_address primary key (addressId))";
String alterTable = "ALTER TABLE "
+ " address ADD CONSTRAINT fk_person FOREIGN KEY (personId) REFERENCES person (personId)";
session.getConnection().createStatement().execute(createPersonTable);
session.getConnection().createStatement().execute(createAddressTable);
session.getConnection().createStatement().execute(alterTable);
}
@Test
public void whenPersonAdressSaved_ThenPersonAddressCanBeQueried() {
Person person = new Person("Baljeet S");
Address address = new Address("Pune");
PersonMapper personMapper = session.getMapper(PersonMapper.class);
Integer id = personMapper.save(person);
address.setPersonId(id);
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
addressMapper.saveAddress(address);
Person returnedPerson = personMapper.getPersonById(id);
assertEquals("Baljeet S", returnedPerson.getName());
assertEquals("Pune", returnedPerson.getAddresses().get(0).getStreetAddress());
}
@Test
public void whenPersonSaved_ThenPersonCanBeQueried() {
Person person = new Person("Baljeet S");
Address address = new Address("Pune");
PersonMapper personMapper = session.getMapper(PersonMapper.class);
Integer id = personMapper.save(person);
address.setPersonId(id);
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
addressMapper.saveAddress(address);
Person returnedPerson = personMapper.getPerson(id);
assertEquals("Baljeet S", returnedPerson.getName());
}
@Test
public void whenPersonUpdated_ThenPersonIsChanged() {
Person person = new Person("Baljeet S");
Address address = new Address("Pune");
PersonMapper personMapper = session.getMapper(PersonMapper.class);
Integer id = personMapper.save(person);
address.setPersonId(id);
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
addressMapper.saveAddress(address);
personMapper.updatePerson(new Person(id, "Baljeet1"));
Person returnedPerson = personMapper.getPerson(id);
assertEquals("Baljeet1", returnedPerson.getName());
}
@Test
public void whenPersoSaved_ThenMapIsReturned() {
Person person = new Person("Baljeet S");
Address address = new Address("Pune");
PersonMapper personMapper = session.getMapper(PersonMapper.class);
Integer id = personMapper.save(person);
address.setPersonId(id);
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
addressMapper.saveAddress(address);
Map<Integer, Person> returnedPerson = personMapper.getAllPerson();
assertEquals(1, returnedPerson.size());
}
@Test
public void whenPersonSearched_ThenResultIsReturned() {
Person person = new Person("Baljeet S");
Address address = new Address("Pune");
PersonMapper personMapper = session.getMapper(PersonMapper.class);
Integer id = personMapper.save(person);
address.setPersonId(id);
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
addressMapper.saveAddress(address);
Person returnedPerson = personMapper.getPersonByName("Baljeet S");
assertEquals("Baljeet S", returnedPerson.getName());
}
@Test
public void whenAddressSearched_ThenResultIsReturned() {
Person person = new Person("Baljeet S");
Address address = new Address("Pune");
PersonMapper personMapper = session.getMapper(PersonMapper.class);
Integer id = personMapper.save(person);
address.setPersonId(id);
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
Integer addressId = addressMapper.saveAddress(address);
Address returnedAddress = addressMapper.getAddresses(addressId);
assertEquals("Pune", returnedAddress.getStreetAddress());
}
@After
public void cleanup() throws SQLException {
session.getConnection().createStatement().execute("drop table address");
session.getConnection().createStatement().execute("drop table person");
session.close();
}
}

View File

@ -37,11 +37,23 @@
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-tools</artifactId> <artifactId>pdfbox-tools</artifactId>
<version>${pdfbox-tools.version}</version> <version>${pdfbox-tools.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sf.cssbox</groupId> <groupId>net.sf.cssbox</groupId>
<artifactId>pdf2dom</artifactId> <artifactId>pdf2dom</artifactId>
<version>${pdf2dom.version}</version> <version>${pdf2dom.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.itextpdf</groupId> <groupId>com.itextpdf</groupId>

View File

@ -226,7 +226,7 @@
<version>1.6.0</version> <version>1.6.0</version>
<configuration> <configuration>
<executable>maven</executable> <executable>maven</executable>
<module>hibernate5</module>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -91,6 +91,12 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>${spring.version}</version> <version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,3 +1,4 @@
### Relevant articles ### Relevant articles
- [Introduction to Ratpack](http://www.baeldung.com/ratpack) - [Introduction to Ratpack](http://www.baeldung.com/ratpack)
- [Ratpack Google Guice Integration](http://www.baeldung.com/ratpack-google-guice)

View File

@ -71,12 +71,6 @@
<version>${logback.version}</version> <version>${logback.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId> <artifactId>httpcore</artifactId>
@ -151,6 +145,12 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${httpclient.version}</version> <version>${httpclient.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
@ -184,6 +184,12 @@
<groupId>com.github.fge</groupId> <groupId>com.github.fge</groupId>
<artifactId>json-schema-core</artifactId> <artifactId>json-schema-core</artifactId>
<version>${json-schema-core.version}</version> <version>${json-schema-core.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@ -282,7 +288,6 @@
<commons-lang3.version>3.5</commons-lang3.version> <commons-lang3.version>3.5</commons-lang3.version>
<commons-logging.version>1.2</commons-logging.version>
<commons-collections.version>3.2.2</commons-collections.version> <commons-collections.version>3.2.2</commons-collections.version>
<httpcore.version>4.4.5</httpcore.version> <httpcore.version>4.4.5</httpcore.version>

View File

@ -9,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/) - [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)
- [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) - [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock)
- [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing) - [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing)
- [Testing a REST API with JBehave](http://www.baeldung.com/jbehave-rest-testing)

View File

@ -35,6 +35,12 @@
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${httpclient.version}</version> <version>${httpclient.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
@ -69,11 +75,6 @@
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- test scoped --> <!-- test scoped -->

View File

@ -6,3 +6,4 @@
### Relevant Articles: ### Relevant Articles:
- [A Guide to RESTEasy](http://www.baeldung.com/resteasy-tutorial) - [A Guide to RESTEasy](http://www.baeldung.com/resteasy-tutorial)
- [RESTEasy Client API](http://www.baeldung.com/resteasy-client-tutorial) - [RESTEasy Client API](http://www.baeldung.com/resteasy-client-tutorial)
- [CORS in JAX-RS](http://www.baeldung.com/cors-in-jax-rs)

View File

@ -67,6 +67,12 @@
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId> <artifactId>resteasy-servlet-initializer</artifactId>
<version>${resteasy.version}</version> <version>${resteasy.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>

View File

@ -56,6 +56,12 @@
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId> <artifactId>selenium-java</artifactId>
<version>${selenium-java.version}</version> <version>${selenium-java.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

3
solr/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant articles
- [Full-text Search with Solr](http://www.baeldung.com/full-text-search-with-solr)

View File

@ -20,11 +20,6 @@
<artifactId>solr-solrj</artifactId> <artifactId>solr-solrj</artifactId>
<version>6.4.1</version> <version>6.4.1</version>
</dependency> </dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -6,3 +6,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles ### Relevant Articles
- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests) - [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)

View File

@ -12,6 +12,12 @@
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -20,3 +20,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [A Guide to the Spring Task Scheduler](http://www.baeldung.com/spring-task-scheduler) - [A Guide to the Spring Task Scheduler](http://www.baeldung.com/spring-task-scheduler)
- [Guide to Spring Retry](http://www.baeldung.com/spring-retry) - [Guide to Spring Retry](http://www.baeldung.com/spring-retry)
- [Custom Scope in Spring](http://www.baeldung.com/spring-custom-scope) - [Custom Scope in Spring](http://www.baeldung.com/spring-custom-scope)
- [New in Guava 21 common.util.concurrent](http://www.baeldung.com/guava-21-util-concurrent)
- [A CLI with Spring Shell](http://www.baeldung.com/spring-shell-cli)
- [JasperReports with Spring](http://www.baeldung.com/spring-jasper)

View File

@ -25,6 +25,12 @@
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
@ -111,6 +117,12 @@
<groupId>net.sf.jasperreports</groupId> <groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId> <artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version> <version>${jasperreports.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- logging --> <!-- logging -->
@ -129,10 +141,6 @@
<artifactId>jcl-over-slf4j</artifactId> <artifactId>jcl-over-slf4j</artifactId>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl --> <!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<!-- test scoped --> <!-- test scoped -->

View File

@ -2,14 +2,16 @@ package org.baeldung.scopes;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@Controller @Controller
public class ScopesController { public class ScopesController {
public static final Logger LOG = Logger.getLogger(ScopesController.class); public static final Logger LOG = LoggerFactory.getLogger(ScopesController.class);
@Resource(name = "requestMessage") @Resource(name = "requestMessage")
HelloMessageGenerator requestMessage; HelloMessageGenerator requestMessage;

View File

@ -1,6 +1,8 @@
package org.baeldung.startup; package org.baeldung.startup;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -11,7 +13,7 @@ import javax.annotation.PostConstruct;
@Scope(value = "prototype") @Scope(value = "prototype")
public class AllStrategiesExampleBean implements InitializingBean { public class AllStrategiesExampleBean implements InitializingBean {
private static final Logger LOG = Logger.getLogger(AllStrategiesExampleBean.class); private static final Logger LOG = LoggerFactory.getLogger(AllStrategiesExampleBean.class);
public AllStrategiesExampleBean() { public AllStrategiesExampleBean() {
LOG.info("Constructor"); LOG.info("Constructor");

View File

@ -1,13 +1,15 @@
package org.baeldung.startup; package org.baeldung.startup;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class EventListenerExampleBean { public class EventListenerExampleBean {
private static final Logger LOG = Logger.getLogger(EventListenerExampleBean.class); private static final Logger LOG = LoggerFactory.getLogger(EventListenerExampleBean.class);
public static int counter; public static int counter;

View File

@ -1,23 +1,24 @@
package org.baeldung.startup; package org.baeldung.startup;
import org.apache.log4j.Logger; import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component @Component
@Scope(value = "prototype") @Scope(value = "prototype")
public class InitMethodExampleBean { public class InitMethodExampleBean {
private static final Logger LOG = Logger.getLogger(InitMethodExampleBean.class); private static final Logger LOG = LoggerFactory.getLogger(InitMethodExampleBean.class);
@Autowired @Autowired
private Environment environment; private Environment environment;
public void init() { public void init() {
LOG.info(Arrays.asList(environment.getDefaultProfiles())); LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles()));
} }
} }

View File

@ -1,25 +1,26 @@
package org.baeldung.startup; package org.baeldung.startup;
import org.apache.log4j.Logger; import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component @Component
@Scope(value = "prototype") @Scope(value = "prototype")
public class InitializingBeanExampleBean implements InitializingBean { public class InitializingBeanExampleBean implements InitializingBean {
private static final Logger LOG = Logger.getLogger(InitializingBeanExampleBean.class); private static final Logger LOG = LoggerFactory.getLogger(InitializingBeanExampleBean.class);
@Autowired @Autowired
private Environment environment; private Environment environment;
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
LOG.info(Arrays.asList(environment.getDefaultProfiles())); LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles()));
} }
} }

View File

@ -1,25 +1,22 @@
package org.baeldung.startup; package org.baeldung.startup;
import org.apache.log4j.Logger; import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component @Component
@Scope(value = "prototype") @Scope(value = "prototype")
public class LogicInConstructorExampleBean { public class LogicInConstructorExampleBean {
private static final Logger LOG = Logger.getLogger(LogicInConstructorExampleBean.class); private static final Logger LOG = LoggerFactory.getLogger(LogicInConstructorExampleBean.class);
private final Environment environment;
@Autowired @Autowired
public LogicInConstructorExampleBean(Environment environment) { public LogicInConstructorExampleBean(Environment environment) {
this.environment = environment; LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles()));
LOG.info(Arrays.asList(environment.getDefaultProfiles()));
} }
} }

View File

@ -1,25 +1,27 @@
package org.baeldung.startup; package org.baeldung.startup;
import org.apache.log4j.Logger; import java.util.Arrays;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Arrays;
@Component @Component
@Scope(value = "prototype") @Scope(value = "prototype")
public class PostConstructExampleBean { public class PostConstructExampleBean {
private static final Logger LOG = Logger.getLogger(PostConstructExampleBean.class); private static final Logger LOG = LoggerFactory.getLogger(PostConstructExampleBean.class);
@Autowired @Autowired
private Environment environment; private Environment environment;
@PostConstruct @PostConstruct
public void init() { public void init() {
LOG.info(Arrays.asList(environment.getDefaultProfiles())); LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles()));
} }
} }

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