diff --git a/.gitignore b/.gitignore index f3fa30f3e3..60c38ed8f5 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ spring-openid/src/main/resources/application.properties .recommenders/ /spring-hibernate4/nbproject/ spring-security-openid/src/main/resources/application.properties + +spring-all/*.log diff --git a/algorithms/README.md b/algorithms/README.md index 00e0646f47..f1e12ee243 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -5,3 +5,4 @@ - [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) - [Introduction to Jenetics Library](http://www.baeldung.com/jenetics) +- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers) diff --git a/apache-cxf/cxf-aegis/src/test/java/com/baeldung/cxf/aegis/BaeldungTest.java b/apache-cxf/cxf-aegis/src/test/java/com/baeldung/cxf/aegis/BaeldungTest.java index 559de037a9..935b283cb4 100644 --- a/apache-cxf/cxf-aegis/src/test/java/com/baeldung/cxf/aegis/BaeldungTest.java +++ b/apache-cxf/cxf-aegis/src/test/java/com/baeldung/cxf/aegis/BaeldungTest.java @@ -3,8 +3,10 @@ package com.baeldung.cxf.aegis; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import org.junit.After; import org.junit.Test; +import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.lang.reflect.Type; @@ -90,4 +92,12 @@ public class BaeldungTest { xmlReader.close(); return courseRepo; } + + @After + public void cleanup(){ + File testFile = new File(fileName); + if (testFile.exists()) { + testFile.delete(); + } + } } \ No newline at end of file diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index c3095be5a5..61a5132f19 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -54,6 +54,12 @@ org.apache.httpcomponents httpclient ${httpclient.version} + + + commons-logging + commons-logging + + diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 79a7650ced..dffcc3ee1b 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -24,6 +24,12 @@ org.springframework spring-context ${spring.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/apache-fop/pom.xml b/apache-fop/pom.xml index 6075c23d21..2de9611ad1 100644 --- a/apache-fop/pom.xml +++ b/apache-fop/pom.xml @@ -28,11 +28,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - @@ -78,6 +73,10 @@ org.apache.avalon.framework avalon-framework-impl + + commons-logging + commons-logging + @@ -90,6 +89,12 @@ avalon-framework avalon-framework-impl ${avalon-framework.version} + + + commons-logging + commons-logging + + diff --git a/apache-poi/pom.xml b/apache-poi/pom.xml index d8a2cc72e0..b619d3adcb 100644 --- a/apache-poi/pom.xml +++ b/apache-poi/pom.xml @@ -42,6 +42,12 @@ org.jxls jxls-jexcel ${jexcel.version} + + + commons-logging + commons-logging + + diff --git a/apache-poi/src/test/java/com/baeldung/jexcel/JExcelTest.java b/apache-poi/src/test/java/com/baeldung/jexcel/JExcelTest.java index 8ee465be34..72272913d5 100644 --- a/apache-poi/src/test/java/com/baeldung/jexcel/JExcelTest.java +++ b/apache-poi/src/test/java/com/baeldung/jexcel/JExcelTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.Before; +import org.junit.After; public class JExcelTest { @@ -53,4 +54,11 @@ public class JExcelTest { .get(1)); } + @After + public void cleanup(){ + File testFile = new File(fileLocation); + if (testFile.exists()) { + testFile.delete(); + } + } } \ No newline at end of file diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/ExcelTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/ExcelTest.java index 34fa64dd94..ad36f46f02 100644 --- a/apache-poi/src/test/java/com/baeldung/poi/excel/ExcelTest.java +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/ExcelTest.java @@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.Before; +import org.junit.After; public class ExcelTest { @@ -50,4 +51,11 @@ public class ExcelTest { .get(1)); } + @After + public void cleanup(){ + File testFile = new File(fileLocation); + if (testFile.exists()) { + testFile.delete(); + } + } } \ No newline at end of file diff --git a/apache-poi/temp.xls b/apache-poi/temp.xls deleted file mode 100644 index 1fad76d88d..0000000000 Binary files a/apache-poi/temp.xls and /dev/null differ diff --git a/apache-poi/temp.xlsx b/apache-poi/temp.xlsx deleted file mode 100644 index 431a8a662c..0000000000 Binary files a/apache-poi/temp.xlsx and /dev/null differ diff --git a/apache-thrift/pom.xml b/apache-thrift/pom.xml index 66cfb2bb41..e275dc0636 100644 --- a/apache-thrift/pom.xml +++ b/apache-thrift/pom.xml @@ -19,6 +19,12 @@ org.apache.thrift libthrift ${thrift.version} + + + commons-logging + commons-logging + + diff --git a/apache-velocity/pom.xml b/apache-velocity/pom.xml index 08f0e96a58..06cfeabfa8 100644 --- a/apache-velocity/pom.xml +++ b/apache-velocity/pom.xml @@ -38,7 +38,7 @@ org.apache.velocity velocity-tools - ${velocity-tools-version} + ${velocity-tools-version} org.slf4j @@ -55,6 +55,12 @@ httpclient ${org.apache.httpcomponents.version} test + + + commons-logging + commons-logging + + diff --git a/aspectj/pom.xml b/aspectj/pom.xml index cbc98dac81..2ef2ae9df7 100644 --- a/aspectj/pom.xml +++ b/aspectj/pom.xml @@ -58,7 +58,7 @@ org.springframework spring-core - 4.3.4.RELEASE + 4.3.4.RELEASE cglib diff --git a/aws/pom.xml b/aws/pom.xml index 681b76cfd4..b493dc58e8 100644 --- a/aws/pom.xml +++ b/aws/pom.xml @@ -19,12 +19,24 @@ com.amazonaws aws-lambda-java-core ${aws-lambda-java-core.version} + + + commons-logging + commons-logging + + com.amazonaws aws-lambda-java-events ${aws-lambda-java-events.version} + + + commons-logging + commons-logging + + diff --git a/cdi/pom.xml b/cdi/pom.xml index e5aaeb2c7b..d2fcec59d7 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -12,6 +12,12 @@ org.springframework spring-core ${spring.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/core-java-9/README.md b/core-java-9/README.md index a6cda8e883..3e82ffe14b 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -12,3 +12,4 @@ - [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) - [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) diff --git a/core-java/README.md b/core-java/README.md index 45695f13f6..910e0fbbec 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -92,3 +92,9 @@ - [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) - [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) diff --git a/core-java/pom.xml b/core-java/pom.xml index d2fa1cdd2e..b4741d5b80 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -92,11 +92,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - org.projectlombok lombok @@ -176,6 +171,12 @@ org.owasp.esapi esapi 2.1.0.1 + + + commons-logging + commons-logging + + diff --git a/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java new file mode 100644 index 0000000000..a498d08041 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java @@ -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 transferQueue; + private final String name; + private final int numberOfMessagesToConsume; + public final AtomicInteger numberOfConsumedMessages = new AtomicInteger(); + + public Consumer(TransferQueue 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); + } +} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/transferqueue/Producer.java b/core-java/src/main/java/com/baeldung/transferqueue/Producer.java new file mode 100644 index 0000000000..c9edc69e33 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/transferqueue/Producer.java @@ -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 transferQueue; + private final String name; + private final Integer numberOfMessagesToProduce; + public final AtomicInteger numberOfProducedMessages = new AtomicInteger(); + + public Producer(TransferQueue 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(); + } + } + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueTest.java b/core-java/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueTest.java new file mode 100644 index 0000000000..5d73e02e4f --- /dev/null +++ b/core-java/src/test/java/com/baeldung/synchronousqueue/SynchronousQueueTest.java @@ -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 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); + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java b/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java new file mode 100644 index 0000000000..4a1a663ce4 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java @@ -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 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 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 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); + } +} diff --git a/core-java/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java b/core-java/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java index e615e6a7d1..e8007ad4c4 100644 --- a/core-java/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java +++ b/core-java/src/test/java/org/baeldung/core/exceptions/FileNotFoundExceptionUnitTest.java @@ -6,12 +6,14 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.junit.Test; 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()); diff --git a/couchbase-sdk/pom.xml b/couchbase-sdk/pom.xml index 1200fab454..d592a15745 100644 --- a/couchbase-sdk/pom.xml +++ b/couchbase-sdk/pom.xml @@ -22,11 +22,23 @@ org.springframework spring-context ${spring-framework.version} + + + commons-logging + commons-logging + + org.springframework spring-context-support ${spring-framework.version} + + + commons-logging + commons-logging + + @@ -46,11 +58,6 @@ jcl-over-slf4j ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/cucumber/README.md b/cucumber/README.md new file mode 100644 index 0000000000..5466d5c561 --- /dev/null +++ b/cucumber/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Cucumber and Scenario Outline](http://www.baeldung.com/cucumber-scenario-outline) diff --git a/deltaspike/pom.xml b/deltaspike/pom.xml index 141b5b0da6..8135ced13a 100644 --- a/deltaspike/pom.xml +++ b/deltaspike/pom.xml @@ -201,12 +201,6 @@ querydsl-jpa ${querydsl.version} - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - diff --git a/disruptor/pom.xml b/disruptor/pom.xml index 2523cc2125..865a87596a 100644 --- a/disruptor/pom.xml +++ b/disruptor/pom.xml @@ -40,11 +40,6 @@ jcl-over-slf4j ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/feign/pom.xml b/feign/pom.xml index 160f37ec2c..de086a3e43 100644 --- a/feign/pom.xml +++ b/feign/pom.xml @@ -18,7 +18,6 @@ UTF-8 9.4.0 1.7.21 - 2.7 1.16.12 4.12 3.6.0 @@ -52,16 +51,6 @@ slf4j-api ${slf4j.version} - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - org.projectlombok lombok diff --git a/feign/src/main/resources/log4j2.xml b/feign/src/main/resources/log4j2.xml deleted file mode 100644 index 659c5fda0e..0000000000 --- a/feign/src/main/resources/log4j2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/groovy-spock/README.md b/groovy-spock/README.md new file mode 100644 index 0000000000..18d26e8fc0 --- /dev/null +++ b/groovy-spock/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock) diff --git a/guava/pom.xml b/guava/pom.xml index 0edbb90efd..447ee47cfc 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -76,11 +76,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/guava21/README.md b/guava21/README.md index ff12555376..8725352d69 100644 --- a/guava21/README.md +++ b/guava21/README.md @@ -1 +1,2 @@ -## Relevant articles: +### Relevant articles: +- [New Stream, Comparator and Collector Functionality in Guava 21](http://www.baeldung.com/guava-21-new) diff --git a/handling-spring-static-resources/pom.xml b/handling-spring-static-resources/pom.xml index 9a14ce9372..1e892ed237 100644 --- a/handling-spring-static-resources/pom.xml +++ b/handling-spring-static-resources/pom.xml @@ -155,11 +155,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/hbase/pom.xml b/hbase/pom.xml index 9d523abf1a..c692054f0f 100644 --- a/hbase/pom.xml +++ b/hbase/pom.xml @@ -28,6 +28,12 @@ org.apache.hbase hbase-client ${hbase.version} + + + commons-logging + commons-logging + + org.apache.hbase diff --git a/hibernate5/pom.xml b/hibernate5/pom.xml new file mode 100644 index 0000000000..b7473ec5b7 --- /dev/null +++ b/hibernate5/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + com.baeldung + hibernate5 + 0.0.1-SNAPSHOT + hibernate5 + http://maven.apache.org + + UTF-8 + + 3.6.0 + + + + org.hibernate + hibernate-core + 5.2.9.Final + + + junit + junit + 4.12 + + + com.h2database + h2 + 1.4.194 + + + + hibernate5 + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + + + diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/App.java b/hibernate5/src/main/java/com/baeldung/hibernate/App.java new file mode 100644 index 0000000000..26a40bb782 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/App.java @@ -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(); + } + + } +} diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/ConfigurableMultiTenantConnectionProvider.java b/hibernate5/src/main/java/com/baeldung/hibernate/ConfigurableMultiTenantConnectionProvider.java new file mode 100644 index 0000000000..b9ed2bd139 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/ConfigurableMultiTenantConnectionProvider.java @@ -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 connectionProviderMap = + new HashMap<>(); + + + public ConfigurableMultiTenantConnectionProvider( + Map 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; + } + +} \ No newline at end of file diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateMultiTenantUtil.java b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateMultiTenantUtil.java new file mode 100644 index 0000000000..c3e7b621d0 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateMultiTenantUtil.java @@ -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 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 setUpConnectionProviders(Properties properties, String[] tenantNames) throws UnsupportedTenancyException { + Map 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"; + +} diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..c1f7301d46 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -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; + } +} \ No newline at end of file diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/hibernate5/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java new file mode 100644 index 0000000000..99d9505ea3 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate; + +public class UnsupportedTenancyException extends Exception { + public UnsupportedTenancyException (String message) { + super(message); + } + +} diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Supplier.java b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Supplier.java new file mode 100644 index 0000000000..d0187bba47 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Supplier.java @@ -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()); + } +} diff --git a/hibernate5/src/main/java/hibernate.cfg.xml b/hibernate5/src/main/java/hibernate.cfg.xml new file mode 100644 index 0000000000..26be05f931 --- /dev/null +++ b/hibernate5/src/main/java/hibernate.cfg.xml @@ -0,0 +1,14 @@ + + + + + org.h2.Driver + jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 + sa + + org.hibernate.dialect.H2Dialect + DATABASE + + diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/MultiTenantHibernateTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/MultiTenantHibernateTest.java new file mode 100644 index 0000000000..4a701de48d --- /dev/null +++ b/hibernate5/src/test/java/com/baeldung/hibernate/MultiTenantHibernateTest.java @@ -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(); + } +} diff --git a/httpclient/pom.xml b/httpclient/pom.xml index eec705b224..976f04c9c2 100644 --- a/httpclient/pom.xml +++ b/httpclient/pom.xml @@ -41,6 +41,12 @@ org.apache.httpcomponents fluent-hc ${httpclient.version} + + + commons-logging + commons-logging + + @@ -59,6 +65,12 @@ org.apache.httpcomponents httpasyncclient ${httpasyncclient.version} + + + commons-logging + commons-logging + + @@ -80,11 +92,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/hystrix/pom.xml b/hystrix/pom.xml index ba1a596631..5ccc66709f 100644 --- a/hystrix/pom.xml +++ b/hystrix/pom.xml @@ -56,6 +56,12 @@ com.netflix.hystrix hystrix-core ${hystrix-core.version} + + + commons-logging + commons-logging + + com.netflix.hystrix diff --git a/image-processing/pom.xml b/image-processing/pom.xml index 8766da571e..1e19686be2 100644 --- a/image-processing/pom.xml +++ b/image-processing/pom.xml @@ -17,11 +17,23 @@ net.imagej ij ${ij.version} + + + commons-logging + commons-logging + + org.openimaj core-image ${core-image.version} + + + commons-logging + commons-logging + + diff --git a/jackson/README.md b/jackson/README.md index 5bc16e66b7..51919f6769 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -27,3 +27,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat) - [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional) - [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map) +- [Jackson Streaming API](http://www.baeldung.com/jackson-streaming-api) diff --git a/jackson/pom.xml b/jackson/pom.xml index 8e627c146b..df2f65d359 100644 --- a/jackson/pom.xml +++ b/jackson/pom.xml @@ -154,11 +154,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/java-cassandra/pom.xml b/java-cassandra/pom.xml index 5796043b95..dfc5452617 100644 --- a/java-cassandra/pom.xml +++ b/java-cassandra/pom.xml @@ -49,11 +49,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - junit diff --git a/javaslang/README.md b/javaslang/README.md index e451883516..fe413fc275 100644 --- a/javaslang/README.md +++ b/javaslang/README.md @@ -2,3 +2,4 @@ - [Introduction to Javaslang](http://www.baeldung.com/javaslang) - [Guide to Try in Javaslang](http://www.baeldung.com/javaslang-try) - [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) diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index 68a1b9c441..c5eeafbab3 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/pom.xml @@ -49,6 +49,12 @@ httpclient ${org.apache.httpcomponents.version} test + + + commons-logging + commons-logging + + diff --git a/jaxb/pom.xml b/jaxb/pom.xml index b636a4dc82..75b98c8c51 100644 --- a/jaxb/pom.xml +++ b/jaxb/pom.xml @@ -135,6 +135,9 @@ ${basedir}/src/main/java false + true + true + false diff --git a/jaxb/src/main/java/com/baeldung/jaxb/gen/ObjectFactory.java b/jaxb/src/main/java/com/baeldung/jaxb/gen/ObjectFactory.java new file mode 100644 index 0000000000..0a3da677ce --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/gen/ObjectFactory.java @@ -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. + *

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(); + } + +} diff --git a/jaxb/src/main/java/com/baeldung/jaxb/gen/UserRequest.java b/jaxb/src/main/java/com/baeldung/jaxb/gen/UserRequest.java new file mode 100644 index 0000000000..1c1abc61a6 --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/gen/UserRequest.java @@ -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; + + +/** + *

Java class for UserRequest complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="UserRequest">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@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; + } + +} diff --git a/jaxb/src/main/java/com/baeldung/jaxb/gen/UserResponse.java b/jaxb/src/main/java/com/baeldung/jaxb/gen/UserResponse.java new file mode 100644 index 0000000000..b80405e4a9 --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/gen/UserResponse.java @@ -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; + + +/** + *

Java class for UserResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="UserResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="gender" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         <element name="created" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@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; + } + +} diff --git a/jaxb/src/main/java/com/baeldung/jaxb/gen/package-info.java b/jaxb/src/main/java/com/baeldung/jaxb/gen/package-info.java new file mode 100644 index 0000000000..639d00179c --- /dev/null +++ b/jaxb/src/main/java/com/baeldung/jaxb/gen/package-info.java @@ -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; diff --git a/jaxb/src/main/java/org/w3/_2001/xmlschema/Adapter1.java b/jaxb/src/main/java/org/w3/_2001/xmlschema/Adapter1.java new file mode 100644 index 0000000000..54b3c360dc --- /dev/null +++ b/jaxb/src/main/java/org/w3/_2001/xmlschema/Adapter1.java @@ -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 +{ + + + 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)); + } + +} diff --git a/jee7/README.md b/jee7/README.md index bc242c3340..8381bcbf34 100644 --- a/jee7/README.md +++ b/jee7/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [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) +- [Converters, Listeners and Validators in Java EE 7](http://www.baeldung.com/java-ee7-converter-listener-validator) diff --git a/jhipster/README.md b/jhipster/README.md index d45796d867..d321e9e81e 100644 --- a/jhipster/README.md +++ b/jhipster/README.md @@ -1,3 +1,8 @@ +### Relevant articles + +- [Intro to JHipster](http://www.baeldung.com/jhipster) + + # 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). diff --git a/jsf/pom.xml b/jsf/pom.xml index 271a869576..a206870f89 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -65,6 +65,12 @@ org.springframework spring-web ${org.springframework.version} + + + commons-logging + commons-logging + + javax.servlet @@ -92,11 +98,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/json/pom.xml b/json/pom.xml index 2b2f80e987..f22626ce70 100644 --- a/json/pom.xml +++ b/json/pom.xml @@ -11,6 +11,12 @@ org.everit.json org.everit.json.schema ${everit.json.schema.version} + + + commons-logging + commons-logging + + diff --git a/jws/README.md b/jws/README.md new file mode 100644 index 0000000000..428d8b650d --- /dev/null +++ b/jws/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [A Guide to the Java Web Start](http://www.baeldung.com/java-web-start) diff --git a/lagom/README b/lagom/README.md similarity index 92% rename from lagom/README rename to lagom/README.md index 0d81a4b3c1..909fe0dff4 100644 --- a/lagom/README +++ b/lagom/README.md @@ -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 1) Create sbt build file "build.sbt" diff --git a/libraries/README.md b/libraries/README.md index 8a32a8b0e7..1cfa7be86c 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -7,6 +7,8 @@ - [Introduction to Javassist](http://www.baeldung.com/javassist) - [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 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. diff --git a/libraries/pom.xml b/libraries/pom.xml index 939d674d97..0643e8257b 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -111,6 +111,12 @@ org.apache.httpcomponents httpclient ${httpclient.version} + + + commons-logging + commons-logging + + commons-io @@ -130,7 +136,7 @@ org.apache.httpcomponents httpclient - ${httpclient.version} + ${httpclient.version} commons-io @@ -141,11 +147,23 @@ org.apache.flink flink-core ${flink.version} + + + commons-logging + commons-logging + + org.apache.flink flink-java ${flink.version} + + + commons-logging + commons-logging + + org.apache.flink @@ -153,6 +171,11 @@ ${flink.version} test + + org.apache.commons + commons-math3 + 3.6.1 + diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/ComplexTests.java b/libraries/src/test/java/com/baeldung/commons/math/ComplexTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/ComplexTests.java rename to libraries/src/test/java/com/baeldung/commons/math/ComplexTests.java diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java b/libraries/src/test/java/com/baeldung/commons/math/FractionTests.java similarity index 89% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java rename to libraries/src/test/java/com/baeldung/commons/math/FractionTests.java index 6efef79b23..6828c8490c 100644 --- a/apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java +++ b/libraries/src/test/java/com/baeldung/commons/math/FractionTests.java @@ -1,7 +1,6 @@ package com.baeldung.commons.math; import org.apache.commons.math3.fraction.Fraction; -import org.apache.commons.math3.fraction.FractionFormat; import org.junit.Assert; import org.junit.Test; diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/GeometryTests.java b/libraries/src/test/java/com/baeldung/commons/math/GeometryTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/GeometryTests.java rename to libraries/src/test/java/com/baeldung/commons/math/GeometryTests.java diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/IntegrationTests.java b/libraries/src/test/java/com/baeldung/commons/math/IntegrationTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/IntegrationTests.java rename to libraries/src/test/java/com/baeldung/commons/math/IntegrationTests.java diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java b/libraries/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java rename to libraries/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java b/libraries/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java rename to libraries/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/RootFindingTests.java b/libraries/src/test/java/com/baeldung/commons/math/RootFindingTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/RootFindingTests.java rename to libraries/src/test/java/com/baeldung/commons/math/RootFindingTests.java diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/StatisticsTests.java b/libraries/src/test/java/com/baeldung/commons/math/StatisticsTests.java similarity index 100% rename from apache-commons-math/src/test/java/com/baeldung/commons/math/StatisticsTests.java rename to libraries/src/test/java/com/baeldung/commons/math/StatisticsTests.java diff --git a/log-mdc/pom.xml b/log-mdc/pom.xml index 931e68a178..10dcb3eaf0 100644 --- a/log-mdc/pom.xml +++ b/log-mdc/pom.xml @@ -13,7 +13,7 @@ org.springframework spring-core - ${springframework.version} + ${springframework.version} org.springframework diff --git a/log4j2/pom.xml b/log4j2/pom.xml index a4c8f19f69..c348982bcf 100644 --- a/log4j2/pom.xml +++ b/log4j2/pom.xml @@ -43,7 +43,7 @@ org.apache.commons commons-dbcp2 - ${commons-dbcp2.version} + ${commons-dbcp2.version} diff --git a/mapstruct/pom.xml b/mapstruct/pom.xml index 72a67d19db..81bcdb4cb9 100644 --- a/mapstruct/pom.xml +++ b/mapstruct/pom.xml @@ -32,6 +32,12 @@ org.springframework spring-context ${springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/mybatis/.gitignore b/mybatis/.gitignore new file mode 100644 index 0000000000..a5ecefc44c --- /dev/null +++ b/mybatis/.gitignore @@ -0,0 +1,16 @@ +*.class + +.settings +.project +*.log + +#folders# +/target +/src/main/webapp/WEB-INF/classes +*/META-INF/* +/testdb1 + +# Packaged files # +*.jar +*.war +*.ear diff --git a/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java b/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java index fb8e15245a..da323a5c24 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java @@ -3,7 +3,6 @@ package com.baeldung.mybatis.utils; import com.baeldung.mybatis.mapper.AddressMapper; import com.baeldung.mybatis.mapper.PersonMapper; import org.apache.ibatis.datasource.pooled.PooledDataSource; -import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.SQL; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; @@ -12,8 +11,6 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import javax.sql.DataSource; -import java.io.IOException; -import java.io.InputStream; public class MyBatisUtil { public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; diff --git a/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java b/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java deleted file mode 100644 index 8dbf7d2589..0000000000 --- a/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java +++ /dev/null @@ -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 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(); - - } - -} diff --git a/pdf/pom.xml b/pdf/pom.xml index 332e1f5244..53232377b5 100644 --- a/pdf/pom.xml +++ b/pdf/pom.xml @@ -37,11 +37,23 @@ org.apache.pdfbox pdfbox-tools ${pdfbox-tools.version} + + + commons-logging + commons-logging + + net.sf.cssbox pdf2dom ${pdf2dom.version} + + + commons-logging + commons-logging + + com.itextpdf diff --git a/pom.xml b/pom.xml index a705ac7cb1..7671d05d75 100644 --- a/pom.xml +++ b/pom.xml @@ -226,7 +226,7 @@ 1.6.0 maven - + hibernate5 @@ -253,4 +253,4 @@ --> - + \ No newline at end of file diff --git a/querydsl/pom.xml b/querydsl/pom.xml index 1335d0f1fd..d6fe7f4191 100644 --- a/querydsl/pom.xml +++ b/querydsl/pom.xml @@ -91,6 +91,12 @@ org.springframework spring-context ${spring.version} + + + commons-logging + commons-logging + + diff --git a/ratpack/README.md b/ratpack/README.md index af473ef0e8..91c8e025f0 100644 --- a/ratpack/README.md +++ b/ratpack/README.md @@ -1,3 +1,4 @@ ### Relevant articles - [Introduction to Ratpack](http://www.baeldung.com/ratpack) +- [Ratpack Google Guice Integration](http://www.baeldung.com/ratpack-google-guice) diff --git a/rest-assured/pom.xml b/rest-assured/pom.xml index 2c8039401e..0c3bf38dc5 100644 --- a/rest-assured/pom.xml +++ b/rest-assured/pom.xml @@ -71,12 +71,6 @@ ${logback.version} - - commons-logging - commons-logging - ${commons-logging.version} - - org.apache.httpcomponents httpcore @@ -151,6 +145,12 @@ org.apache.httpcomponents httpclient ${httpclient.version} + + + commons-logging + commons-logging + + @@ -184,6 +184,12 @@ com.github.fge json-schema-core ${json-schema-core.version} + + + commons-logging + commons-logging + + junit @@ -282,7 +288,6 @@ 3.5 - 1.2 3.2.2 4.4.5 diff --git a/rest-testing/README.md b/rest-testing/README.md index 5dd4e49162..37a53dd815 100644 --- a/rest-testing/README.md +++ b/rest-testing/README.md @@ -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/) - [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) - [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) diff --git a/rest-testing/pom.xml b/rest-testing/pom.xml index 746752133c..a6a9bb39b3 100644 --- a/rest-testing/pom.xml +++ b/rest-testing/pom.xml @@ -35,6 +35,12 @@ org.apache.httpcomponents httpclient ${httpclient.version} + + + commons-logging + commons-logging + + org.apache.httpcomponents @@ -69,11 +75,6 @@ ${org.slf4j.version} runtime - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/resteasy/README.md b/resteasy/README.md index 722f1dfe93..83051037d2 100644 --- a/resteasy/README.md +++ b/resteasy/README.md @@ -6,3 +6,4 @@ ### Relevant Articles: - [A Guide to RESTEasy](http://www.baeldung.com/resteasy-tutorial) - [RESTEasy Client API](http://www.baeldung.com/resteasy-client-tutorial) +- [CORS in JAX-RS](http://www.baeldung.com/cors-in-jax-rs) diff --git a/resteasy/pom.xml b/resteasy/pom.xml index f0bd8298f5..eacde92353 100644 --- a/resteasy/pom.xml +++ b/resteasy/pom.xml @@ -67,6 +67,12 @@ org.jboss.resteasy resteasy-servlet-initializer ${resteasy.version} + + + commons-logging + commons-logging + + diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml index b4490f779b..fceeb6eec6 100644 --- a/selenium-junit-testng/pom.xml +++ b/selenium-junit-testng/pom.xml @@ -56,6 +56,12 @@ org.seleniumhq.selenium selenium-java ${selenium-java.version} + + + commons-logging + commons-logging + + junit diff --git a/solr/README.md b/solr/README.md new file mode 100644 index 0000000000..631a4f44d1 --- /dev/null +++ b/solr/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Full-text Search with Solr](http://www.baeldung.com/full-text-search-with-solr) diff --git a/solr/pom.xml b/solr/pom.xml index e784d87157..cc3a6165fe 100644 --- a/solr/pom.xml +++ b/solr/pom.xml @@ -20,11 +20,6 @@ solr-solrj 6.4.1 - - log4j - log4j - 1.2.16 - junit junit diff --git a/spring-5/README.md b/spring-5/README.md index 47a5314009..31f665f4a2 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -6,3 +6,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles - [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests) +- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web) diff --git a/spring-akka/pom.xml b/spring-akka/pom.xml index 5965213e65..497022064c 100644 --- a/spring-akka/pom.xml +++ b/spring-akka/pom.xml @@ -12,6 +12,12 @@ org.springframework spring-context + + + commons-logging + commons-logging + + diff --git a/spring-all/README.md b/spring-all/README.md index 3493871c78..29be01c79e 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -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) - [Guide to Spring Retry](http://www.baeldung.com/spring-retry) - [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) diff --git a/spring-all/pom.xml b/spring-all/pom.xml index 1b12d7e42c..7fbb6acced 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -25,6 +25,12 @@ org.springframework spring-web + + + commons-logging + commons-logging + + org.springframework @@ -111,6 +117,12 @@ net.sf.jasperreports jasperreports ${jasperreports.version} + + + commons-logging + commons-logging + + @@ -129,10 +141,6 @@ jcl-over-slf4j - - org.slf4j - log4j-over-slf4j - diff --git a/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java b/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java index 1e3d5f3b14..73df386aff 100644 --- a/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java +++ b/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java @@ -2,14 +2,16 @@ package org.baeldung.scopes; 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.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class ScopesController { - public static final Logger LOG = Logger.getLogger(ScopesController.class); + public static final Logger LOG = LoggerFactory.getLogger(ScopesController.class); @Resource(name = "requestMessage") HelloMessageGenerator requestMessage; diff --git a/spring-all/src/main/java/org/baeldung/startup/AllStrategiesExampleBean.java b/spring-all/src/main/java/org/baeldung/startup/AllStrategiesExampleBean.java index d4334437f7..f36b8703ea 100644 --- a/spring-all/src/main/java/org/baeldung/startup/AllStrategiesExampleBean.java +++ b/spring-all/src/main/java/org/baeldung/startup/AllStrategiesExampleBean.java @@ -1,6 +1,8 @@ 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.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -11,7 +13,7 @@ import javax.annotation.PostConstruct; @Scope(value = "prototype") 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() { LOG.info("Constructor"); diff --git a/spring-all/src/main/java/org/baeldung/startup/EventListenerExampleBean.java b/spring-all/src/main/java/org/baeldung/startup/EventListenerExampleBean.java index e9cd1a159d..58e42337cc 100644 --- a/spring-all/src/main/java/org/baeldung/startup/EventListenerExampleBean.java +++ b/spring-all/src/main/java/org/baeldung/startup/EventListenerExampleBean.java @@ -1,13 +1,15 @@ 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.EventListener; import org.springframework.stereotype.Component; @Component 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; diff --git a/spring-all/src/main/java/org/baeldung/startup/InitMethodExampleBean.java b/spring-all/src/main/java/org/baeldung/startup/InitMethodExampleBean.java index cea6b026d6..f3d30011f8 100644 --- a/spring-all/src/main/java/org/baeldung/startup/InitMethodExampleBean.java +++ b/spring-all/src/main/java/org/baeldung/startup/InitMethodExampleBean.java @@ -1,23 +1,24 @@ 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.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import java.util.Arrays; - @Component @Scope(value = "prototype") public class InitMethodExampleBean { - private static final Logger LOG = Logger.getLogger(InitMethodExampleBean.class); + private static final Logger LOG = LoggerFactory.getLogger(InitMethodExampleBean.class); @Autowired private Environment environment; public void init() { - LOG.info(Arrays.asList(environment.getDefaultProfiles())); + LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles())); } } diff --git a/spring-all/src/main/java/org/baeldung/startup/InitializingBeanExampleBean.java b/spring-all/src/main/java/org/baeldung/startup/InitializingBeanExampleBean.java index 33b14864f3..5d6f8c9d88 100644 --- a/spring-all/src/main/java/org/baeldung/startup/InitializingBeanExampleBean.java +++ b/spring-all/src/main/java/org/baeldung/startup/InitializingBeanExampleBean.java @@ -1,25 +1,26 @@ 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.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import java.util.Arrays; - @Component @Scope(value = "prototype") public class InitializingBeanExampleBean implements InitializingBean { - private static final Logger LOG = Logger.getLogger(InitializingBeanExampleBean.class); + private static final Logger LOG = LoggerFactory.getLogger(InitializingBeanExampleBean.class); @Autowired private Environment environment; @Override public void afterPropertiesSet() throws Exception { - LOG.info(Arrays.asList(environment.getDefaultProfiles())); + LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles())); } } diff --git a/spring-all/src/main/java/org/baeldung/startup/LogicInConstructorExampleBean.java b/spring-all/src/main/java/org/baeldung/startup/LogicInConstructorExampleBean.java index 2a7b3e26c7..d25a83942a 100644 --- a/spring-all/src/main/java/org/baeldung/startup/LogicInConstructorExampleBean.java +++ b/spring-all/src/main/java/org/baeldung/startup/LogicInConstructorExampleBean.java @@ -1,25 +1,22 @@ 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.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import java.util.Arrays; - @Component @Scope(value = "prototype") public class LogicInConstructorExampleBean { - private static final Logger LOG = Logger.getLogger(LogicInConstructorExampleBean.class); - - private final Environment environment; + private static final Logger LOG = LoggerFactory.getLogger(LogicInConstructorExampleBean.class); @Autowired public LogicInConstructorExampleBean(Environment environment) { - this.environment = environment; - - LOG.info(Arrays.asList(environment.getDefaultProfiles())); + LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles())); } } diff --git a/spring-all/src/main/java/org/baeldung/startup/PostConstructExampleBean.java b/spring-all/src/main/java/org/baeldung/startup/PostConstructExampleBean.java index 4cabaad4df..2397c3a0a2 100644 --- a/spring-all/src/main/java/org/baeldung/startup/PostConstructExampleBean.java +++ b/spring-all/src/main/java/org/baeldung/startup/PostConstructExampleBean.java @@ -1,25 +1,27 @@ 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.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import java.util.Arrays; - @Component @Scope(value = "prototype") public class PostConstructExampleBean { - private static final Logger LOG = Logger.getLogger(PostConstructExampleBean.class); + private static final Logger LOG = LoggerFactory.getLogger(PostConstructExampleBean.class); @Autowired private Environment environment; @PostConstruct public void init() { - LOG.info(Arrays.asList(environment.getDefaultProfiles())); + LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles())); } } diff --git a/spring-all/src/main/java/org/baeldung/startup/StartupApplicationListenerExample.java b/spring-all/src/main/java/org/baeldung/startup/StartupApplicationListenerExample.java index 32a63f0c1a..e02388dea3 100644 --- a/spring-all/src/main/java/org/baeldung/startup/StartupApplicationListenerExample.java +++ b/spring-all/src/main/java/org/baeldung/startup/StartupApplicationListenerExample.java @@ -1,6 +1,8 @@ package org.baeldung.startup; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; @@ -8,7 +10,7 @@ import org.springframework.stereotype.Component; @Component public class StartupApplicationListenerExample implements ApplicationListener { - private static final Logger LOG = Logger.getLogger(StartupApplicationListenerExample.class); + private static final Logger LOG = LoggerFactory.getLogger(StartupApplicationListenerExample.class); public static int counter; diff --git a/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java b/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java index 0353083943..cc5ac863b5 100644 --- a/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java +++ b/spring-all/src/test/java/org/baeldung/shell/simple/SimpleCLIUnitTest.java @@ -1,6 +1,7 @@ package org.baeldung.shell.simple; import java.io.File; + import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -15,13 +16,18 @@ public class SimpleCLIUnitTest { @BeforeClass public static void startUp() throws InterruptedException { - Bootstrap bootstrap = new Bootstrap(); + final Bootstrap bootstrap = new Bootstrap(); shell = bootstrap.getJLineShellComponent(); } @AfterClass public static void shutdown() { shell.stop(); + // delete contents.txt + final File testFile = new File("contents.txt"); + if (testFile.exists()) { + testFile.delete(); + } } public static JLineShellComponent getShell() { @@ -31,7 +37,7 @@ public class SimpleCLIUnitTest { @Test public void givenCommandConfig_whenExecutingWebGetCommand_thenCorrectResult() { - CommandResult resultWebSave = shell.executeCommand("web-get --url https://www.google.com"); + final CommandResult resultWebSave = shell.executeCommand("web-get --url https://www.google.com"); Assert.assertTrue(resultWebSave.isSuccess()); } @@ -40,37 +46,27 @@ public class SimpleCLIUnitTest { public void givenCommandConfig_whenExecutingWebSaveCommand_thenCorrectResult() { shell.executeCommand("admin-enable"); - CommandResult result = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); + final CommandResult result = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); - Assert.assertArrayEquals( - new boolean[]{ - result.isSuccess(), - new File("contents.txt").exists()}, - new boolean[]{true, true}); + Assert.assertArrayEquals(new boolean[] { result.isSuccess(), new File("contents.txt").exists() }, new boolean[] { true, true }); } @Test public void givenCommandConfig_whenAdminEnableCommandExecuted_thenCorrectAvailability() { - - CommandResult resultAdminDisable = shell.executeCommand("admin-disable"); - CommandResult resultWebSaveUnavailable = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); - CommandResult resultAdminEnable = shell.executeCommand("admin-enable"); - CommandResult resultWebSaveAvailable = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); - Assert.assertArrayEquals( - new boolean[]{ - resultAdminDisable.isSuccess(), - resultWebSaveUnavailable.isSuccess(), - resultAdminEnable.isSuccess(), - resultWebSaveAvailable.isSuccess()}, - new boolean[]{true, false, true, true}); + final CommandResult resultAdminDisable = shell.executeCommand("admin-disable"); + final CommandResult resultWebSaveUnavailable = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); + final CommandResult resultAdminEnable = shell.executeCommand("admin-enable"); + final CommandResult resultWebSaveAvailable = shell.executeCommand("web-save --url https://www.google.com --out contents.txt"); + + Assert.assertArrayEquals(new boolean[] { resultAdminDisable.isSuccess(), resultWebSaveUnavailable.isSuccess(), resultAdminEnable.isSuccess(), resultWebSaveAvailable.isSuccess() }, new boolean[] { true, false, true, true }); } @Test public void givenCommandConfig_whenWebSaveCommandExecutedNoOutArgument_thenError() { shell.executeCommand("admin-enable"); - CommandResult resultWebSave = shell.executeCommand("web-save --url https://www.google.com"); + final CommandResult resultWebSave = shell.executeCommand("web-save --url https://www.google.com"); Assert.assertEquals(resultWebSave.isSuccess(), false); } @@ -78,7 +74,7 @@ public class SimpleCLIUnitTest { @Test public void givenCommandConfig_whenExecutingWebGetCommandWithDefaultArgument_thenCorrectResult() { - CommandResult result = shell.executeCommand("web-get https://www.google.com"); + final CommandResult result = shell.executeCommand("web-get https://www.google.com"); Assert.assertEquals(result.isSuccess(), true); } diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/MessageConsumer.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/MessageConsumer.java index b757dfebe8..6eb13c18f6 100644 --- a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/MessageConsumer.java +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/MessageConsumer.java @@ -1,15 +1,17 @@ package com.baeldung.springamqpsimple; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; @Component public class MessageConsumer { - private static final Logger logger = LogManager.getLogger(MessageConsumer.class); + private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class); + @RabbitListener(queues = {SpringAmqpConfig.queueName}) public void receiveMessage(String message) { logger.info("Received Message: " + message); } -} +} \ No newline at end of file diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java index 78d79dd47a..f6c82b635e 100644 --- a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/SpringAmqpConfig.java @@ -1,6 +1,10 @@ package com.baeldung.springamqpsimple; -import org.springframework.amqp.core.*; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.DirectExchange; +import org.springframework.amqp.core.Exchange; +import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; @@ -32,7 +36,7 @@ public class SpringAmqpConfig { @Bean SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, - MessageListenerAdapter listenerAdapter) { + MessageListenerAdapter listenerAdapter) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames(queueName); @@ -44,5 +48,4 @@ public class SpringAmqpConfig { MessageListenerAdapter listenerAdapter(MessageConsumer messageReceiver) { return new MessageListenerAdapter(messageReceiver, "receiveMessage"); } - } diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java new file mode 100644 index 0000000000..1d02b4dad9 --- /dev/null +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastConfig.java @@ -0,0 +1,70 @@ +package com.baeldung.springamqpsimple.broadcast; + +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.Declarable; +import org.springframework.amqp.core.DirectExchange; +import org.springframework.amqp.core.FanoutExchange; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.core.TopicExchange; +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import java.util.Arrays; +import java.util.List; + +@Configuration +@Profile("!test") +public class BroadcastConfig { + + public final static String fanoutQueue1Name = "com.baeldung.spring-amqp-simple.fanout.queue1"; + public final static String fanoutQueue2Name = "com.baeldung.spring-amqp-simple.fanout.queue2"; + public final static String fanoutExchangeName = "com.baeldung.spring-amqp-simple.fanout.exchange"; + + public final static String topicQueue1Name = "com.baeldung.spring-amqp-simple.topic.queue1"; + public final static String topicQueue2Name = "com.baeldung.spring-amqp-simple.topic.queue2"; + public final static String topicExchangeName = "com.baeldung.spring-amql-simple.topic.exchange"; + + @Bean + public List topicBindings() { + Queue topicQueue1 = new Queue(topicQueue1Name, false); + Queue topicQueue2 = new Queue(topicQueue2Name, false); + + TopicExchange topicExchange = new TopicExchange(topicExchangeName); + + return Arrays.asList( + topicQueue1, + topicQueue2, + topicExchange, + BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"), + BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#") + ); + } + + @Bean + public List fanoutBindings() { + Queue fanoutQueue1 = new Queue(fanoutQueue1Name, false); + Queue fanoutQueue2 = new Queue(fanoutQueue2Name, false); + + FanoutExchange fanoutExchange = new FanoutExchange(fanoutExchangeName); + + return Arrays.asList( + fanoutQueue1, + fanoutQueue2, + fanoutExchange, + BindingBuilder.bind(fanoutQueue1).to(fanoutExchange), + BindingBuilder.bind(fanoutQueue2).to(fanoutExchange) + ); + } + + @Bean + public SimpleRabbitListenerContainerFactory container(ConnectionFactory connectionFactory, SimpleRabbitListenerContainerFactoryConfigurer configurer) { + SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); + configurer.configure(factory, connectionFactory); + return factory; + } + +} diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageConsumers.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageConsumers.java new file mode 100644 index 0000000000..0ae04ea092 --- /dev/null +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageConsumers.java @@ -0,0 +1,32 @@ +package com.baeldung.springamqpsimple.broadcast; + +import com.baeldung.springamqpsimple.MessageConsumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +@Component +public class BroadcastMessageConsumers { + private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class); + + @RabbitListener(queues = {BroadcastConfig.fanoutQueue1Name}) + public void receiveMessageFromFanout1(String message) { + logger.info("Received fanout 1 message: " + message); + } + + @RabbitListener(queues = {BroadcastConfig.fanoutQueue2Name}) + public void receiveMessageFromFanout2(String message) { + logger.info("Received fanout 2 message: " + message); + } + + @RabbitListener(queues = {BroadcastConfig.topicQueue1Name}) + public void receiveMessageFromTopic1(String message) { + logger.info("Received topic 1 message: " + message); + } + + @RabbitListener(queues = {BroadcastConfig.topicQueue2Name}) + public void receiveMessageFromTopic2(String message) { + logger.info("Received topic 2 message: " + message); + } +} diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageController.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageController.java new file mode 100644 index 0000000000..75d4d20e55 --- /dev/null +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageController.java @@ -0,0 +1,26 @@ +package com.baeldung.springamqpsimple.broadcast; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +@Controller +public class BroadcastMessageController { + + private final BroadcastMessageProducer messageProducer; + + @Autowired + public BroadcastMessageController(BroadcastMessageProducer messageProducer) { + this.messageProducer = messageProducer; + } + + @RequestMapping(value="/broadcast", method= RequestMethod.POST) + @ResponseStatus(value= HttpStatus.CREATED) + public void sendMessage(@RequestBody String message) { + messageProducer.sendMessages(message); + } +} diff --git a/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageProducer.java b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageProducer.java new file mode 100644 index 0000000000..590da24962 --- /dev/null +++ b/spring-amqp-simple/src/main/java/com/baeldung/springamqpsimple/broadcast/BroadcastMessageProducer.java @@ -0,0 +1,22 @@ +package com.baeldung.springamqpsimple.broadcast; + +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class BroadcastMessageProducer { + + private final RabbitTemplate rabbitTemplate; + + @Autowired + public BroadcastMessageProducer(RabbitTemplate rabbitTemplate) { + this.rabbitTemplate = rabbitTemplate; + } + + public void sendMessages(String message) { + rabbitTemplate.convertAndSend(BroadcastConfig.fanoutExchangeName, "", message); + rabbitTemplate.convertAndSend(BroadcastConfig.topicExchangeName, "user.not-important.info", message); + rabbitTemplate.convertAndSend(BroadcastConfig.topicExchangeName, "user.important.error", message); + } +} diff --git a/spring-amqp-simple/src/main/resources/application.yaml b/spring-amqp-simple/src/main/resources/application.yaml index 4aca1bb783..47e7a3b9e0 100644 --- a/spring-amqp-simple/src/main/resources/application.yaml +++ b/spring-amqp-simple/src/main/resources/application.yaml @@ -1,4 +1,5 @@ spring: rabbitmq: - username: baeldung - password: baeldung \ No newline at end of file + username: guest + password: guest + host: 10.10.10.105 \ No newline at end of file diff --git a/spring-amqp-simple/src/test/java/broadcast/BroadcastMessageControllerIntegrationTest.java b/spring-amqp-simple/src/test/java/broadcast/BroadcastMessageControllerIntegrationTest.java new file mode 100644 index 0000000000..c3be7f1ede --- /dev/null +++ b/spring-amqp-simple/src/test/java/broadcast/BroadcastMessageControllerIntegrationTest.java @@ -0,0 +1,48 @@ +package broadcast; + +import com.baeldung.springamqpsimple.broadcast.BroadcastConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@RunWith(SpringRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = RANDOM_PORT) +public class BroadcastMessageControllerIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @MockBean + private RabbitTemplate rabbitTemplate; + + @Test + public void whenPostingMessage_thenMessageIsCreated() { + final String message = "Hello World!"; + ResponseEntity responseEntity = restTemplate.postForEntity("/broadcast", message, Void.class); + + assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); + } + + @Test + public void whenPostingMessage_thenMessageIsSentToBroker() { + final String message = "Hello World!"; + restTemplate.postForEntity("/broadcast", message, Void.class); + + verify(rabbitTemplate).convertAndSend(BroadcastConfig.fanoutExchangeName, "", message); + verify(rabbitTemplate).convertAndSend(BroadcastConfig.topicExchangeName, "user.not-important.info", message); + verify(rabbitTemplate).convertAndSend(BroadcastConfig.topicExchangeName, "user.important.error", message); + } +} \ No newline at end of file diff --git a/spring-amqp/pom.xml b/spring-amqp/pom.xml index bb26b2d15d..4eef6070c7 100755 --- a/spring-amqp/pom.xml +++ b/spring-amqp/pom.xml @@ -20,6 +20,12 @@ org.springframework.amqp spring-rabbit 1.6.6.RELEASE + + + commons-logging + commons-logging + + diff --git a/spring-aop/README.md b/spring-aop/README.md new file mode 100644 index 0000000000..28295faf23 --- /dev/null +++ b/spring-aop/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Implementing a Custom Spring AOP Annotation](http://www.baeldung.com/spring-aop-annotation) diff --git a/spring-apache-camel/pom.xml b/spring-apache-camel/pom.xml index da7dad1a1f..0b1b10a730 100644 --- a/spring-apache-camel/pom.xml +++ b/spring-apache-camel/pom.xml @@ -35,6 +35,12 @@ org.apache.camel camel-spring ${env.camel.version} + + + commons-logging + commons-logging + + @@ -48,11 +54,6 @@ spring-context ${env.spring.version} - - org.slf4j - slf4j-log4j12 - 1.7.21 - org.apache.camel camel-spring-javaconfig diff --git a/spring-apache-camel/src/main/resources/log4j.xml b/spring-apache-camel/src/main/resources/log4j.xml deleted file mode 100644 index 4a86fb2357..0000000000 --- a/spring-apache-camel/src/main/resources/log4j.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-batch/pom.xml b/spring-batch/pom.xml index a92a0e8323..8885bd452c 100644 --- a/spring-batch/pom.xml +++ b/spring-batch/pom.xml @@ -27,6 +27,12 @@ org.springframework spring-oxm ${spring.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml new file mode 100644 index 0000000000..62c3676ae4 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml @@ -0,0 +1,59 @@ + + 4.0.0 + + com.baeldung + greeter-spring-boot-autoconfigure + 0.0.1-SNAPSHOT + + + UTF-8 + 1.5.2.RELEASE + 0.0.1-SNAPSHOT + + + + + + org.springframework.boot + spring-boot + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-autoconfigure + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-configuration-processor + ${spring-boot.version} + true + + + + com.baeldung + greeter + ${greeter.version} + true + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/java/com/baeldung/greeter/autoconfigure/GreeterAutoConfiguration.java b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/java/com/baeldung/greeter/autoconfigure/GreeterAutoConfiguration.java new file mode 100644 index 0000000000..4cf078aa00 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/java/com/baeldung/greeter/autoconfigure/GreeterAutoConfiguration.java @@ -0,0 +1,48 @@ +package com.baeldung.greeter.autoconfigure; + +import static com.baeldung.greeter.GreeterConfigParams.*; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.greeter.Greeter; +import com.baeldung.greeter.GreetingConfig; + +@Configuration +@ConditionalOnClass(Greeter.class) +@EnableConfigurationProperties(GreeterProperties.class) +public class GreeterAutoConfiguration { + + @Autowired + private GreeterProperties greeterProperties; + + @Bean + @ConditionalOnMissingBean + public GreetingConfig greeterConfig() { + + String userName = greeterProperties.getUserName() == null ? System.getProperty("user.name") : greeterProperties.getUserName(); + String morningMessage = greeterProperties.getMorningMessage() == null ? "Good Morning" : greeterProperties.getMorningMessage(); + String afternoonMessage = greeterProperties.getAfternoonMessage() == null ? "Good Afternoon" : greeterProperties.getAfternoonMessage(); + String eveningMessage = greeterProperties.getEveningMessage() == null ? "Good Evening" : greeterProperties.getEveningMessage(); + String nightMessage = greeterProperties.getNightMessage() == null ? "Good Night" : greeterProperties.getNightMessage(); + + GreetingConfig greetingConfig = new GreetingConfig(); + greetingConfig.put(USER_NAME, userName); + greetingConfig.put(MORNING_MESSAGE, morningMessage); + greetingConfig.put(AFTERNOON_MESSAGE, afternoonMessage); + greetingConfig.put(EVENING_MESSAGE, eveningMessage); + greetingConfig.put(NIGHT_MESSAGE, nightMessage); + return greetingConfig; + } + + @Bean + @ConditionalOnMissingBean + public Greeter greeter(GreetingConfig greetingConfig) { + return new Greeter(greetingConfig); + } + +} diff --git a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/java/com/baeldung/greeter/autoconfigure/GreeterProperties.java b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/java/com/baeldung/greeter/autoconfigure/GreeterProperties.java new file mode 100644 index 0000000000..c60c45c8c6 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/java/com/baeldung/greeter/autoconfigure/GreeterProperties.java @@ -0,0 +1,54 @@ +package com.baeldung.greeter.autoconfigure; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "baeldung.greeter") +public class GreeterProperties { + + private String userName; + private String morningMessage; + private String afternoonMessage; + private String eveningMessage; + private String nightMessage; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getMorningMessage() { + return morningMessage; + } + + public void setMorningMessage(String morningMessage) { + this.morningMessage = morningMessage; + } + + public String getAfternoonMessage() { + return afternoonMessage; + } + + public void setAfternoonMessage(String afternoonMessage) { + this.afternoonMessage = afternoonMessage; + } + + public String getEveningMessage() { + return eveningMessage; + } + + public void setEveningMessage(String eveningMessage) { + this.eveningMessage = eveningMessage; + } + + public String getNightMessage() { + return nightMessage; + } + + public void setNightMessage(String nightMessage) { + this.nightMessage = nightMessage; + } + +} diff --git a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..418201227b --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.baeldung.greeter.autoconfigure.GreeterAutoConfiguration \ No newline at end of file diff --git a/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml new file mode 100644 index 0000000000..bb1d35cfaa --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + com.baeldung + greeter-spring-boot-sample-app + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 1.5.2.RELEASE + + + + + UTF-8 + 1.8 + 0.0.1-SNAPSHOT + + + + + + com.baeldung + greeter-spring-boot-starter + ${greeter-starter.version} + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + \ No newline at end of file diff --git a/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/java/com/baeldung/greeter/sample/GreeterSampleApplication.java b/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/java/com/baeldung/greeter/sample/GreeterSampleApplication.java new file mode 100644 index 0000000000..3c87524648 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/java/com/baeldung/greeter/sample/GreeterSampleApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.greeter.sample; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import com.baeldung.greeter.Greeter; + +@SpringBootApplication +public class GreeterSampleApplication implements CommandLineRunner { + + @Autowired + private Greeter greeter; + + public static void main(String[] args) { + SpringApplication.run(GreeterSampleApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + String message = greeter.greet(); + System.out.println(message); + } +} diff --git a/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/resources/application.properties b/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/resources/application.properties new file mode 100644 index 0000000000..6136e602f7 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/main/resources/application.properties @@ -0,0 +1,2 @@ +baeldung.greeter.userName=Baeldung +baeldung.greeter.afternoonMessage=Woha\ Afternoon diff --git a/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/com/baeldung/greeter/sample/GreeterSampleApplicationTest.java b/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/com/baeldung/greeter/sample/GreeterSampleApplicationTest.java new file mode 100644 index 0000000000..bdb8fd0112 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/com/baeldung/greeter/sample/GreeterSampleApplicationTest.java @@ -0,0 +1,50 @@ +package com.baeldung.greeter.sample; + +import static org.junit.Assert.assertEquals; + +import java.time.LocalDateTime; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.greeter.Greeter; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = GreeterSampleApplication.class) +public class GreeterSampleApplicationTest { + + @Autowired + private Greeter greeter; + + @Test + public void givenMorningTime_ifMorningMessage_thenSuccess() { + String expected = "Hello Baeldung, Good Morning"; + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 6, 0)); + assertEquals(expected, actual); + } + + @Test + public void givenAfternoonTime_ifAfternoonMessage_thenSuccess() { + String expected = "Hello Baeldung, Woha Afternoon"; + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 13, 0)); + assertEquals(expected, actual); + } + + @Test + public void givenEveningTime_ifEveningMessage_thenSuccess() { + String expected = "Hello Baeldung, Good Evening"; + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 19, 0)); + assertEquals(expected, actual); + } + + @Test + public void givenNightTime_ifNightMessage_thenSuccess() { + String expected = "Hello Baeldung, Good Night"; + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 21, 0)); + assertEquals(expected, actual); + } + +} diff --git a/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml new file mode 100644 index 0000000000..7b38c53c09 --- /dev/null +++ b/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + + com.baeldung + greeter-spring-boot-starter + 0.0.1-SNAPSHOT + + + UTF-8 + 0.0.1-SNAPSHOT + 1.5.2.RELEASE + + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot.version} + + + + com.baeldung + greeter-spring-boot-autoconfigure + ${project.version} + + + + com.baeldung + greeter + ${greeter.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/spring-boot-custom-starter/greeter/README.md b/spring-boot-custom-starter/greeter/README.md new file mode 100644 index 0000000000..3b26cbddcb --- /dev/null +++ b/spring-boot-custom-starter/greeter/README.md @@ -0,0 +1,19 @@ +# Greeter App + +This app takes in the user's name and messages for different times of day as configuration parameters and outptus the greeting messge. For example it will take the name **John** and the message for morning time as **Good Morning** and output the message **Hello John, Good Morning**. + +## Usage + +Create and populate the class `GreetingConfig`, instantiate a `Greeter` using the `GreetingConfig` and use it get greeting messages: + +```java +GreetingConfig greetingConfig = new GreetingConfig(); +greetingConfig.put(USER_NAME, "World"); +greetingConfig.put(MORNING_MESSAGE, "Good Morning"); +greetingConfig.put(AFTERNOON_MESSAGE, "Good Afternoon"); +greetingConfig.put(EVENING_MESSAGE, "Good Evening"); +greetingConfig.put(NIGHT_MESSAGE, "Good Night"); + +Greeter greeter = new Greeter(greetingConfig); +greeter.greet(); +``` \ No newline at end of file diff --git a/apache-commons-math/pom.xml b/spring-boot-custom-starter/greeter/pom.xml similarity index 51% rename from apache-commons-math/pom.xml rename to spring-boot-custom-starter/greeter/pom.xml index 98c6953120..b0e37a9ed9 100644 --- a/apache-commons-math/pom.xml +++ b/spring-boot-custom-starter/greeter/pom.xml @@ -1,23 +1,32 @@ - - + 4.0.0 com.baeldung - apache-commons-math - 1.0-SNAPSHOT + greeter + 0.0.1-SNAPSHOT - 3.6.0 + UTF-8 + + + + junit + junit + 4.12 + test + + + + org.apache.maven.plugins maven-compiler-plugin - ${maven-compiler-plugin.version} + 3.5.1 1.8 1.8 @@ -26,19 +35,4 @@ - - - org.apache.commons - commons-math3 - 3.6.1 - - - - junit - junit - 4.12 - test - - - \ No newline at end of file diff --git a/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/Greeter.java b/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/Greeter.java new file mode 100644 index 0000000000..970561d1fd --- /dev/null +++ b/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/Greeter.java @@ -0,0 +1,35 @@ +package com.baeldung.greeter; + +import static com.baeldung.greeter.GreeterConfigParams.*; + +import java.time.LocalDateTime; + +public class Greeter { + + private GreetingConfig greetingConfig; + + public Greeter(GreetingConfig greetingConfig) { + this.greetingConfig = greetingConfig; + } + + public String greet(LocalDateTime localDateTime) { + + String name = greetingConfig.getProperty(USER_NAME); + int hourOfDay = localDateTime.getHour(); + + if (hourOfDay >= 5 && hourOfDay < 12) { + return String.format("Hello %s, %s", name, greetingConfig.get(MORNING_MESSAGE)); + } else if (hourOfDay >= 12 && hourOfDay < 17) { + return String.format("Hello %s, %s", name, greetingConfig.get(AFTERNOON_MESSAGE)); + } else if (hourOfDay >= 17 && hourOfDay < 20) { + return String.format("Hello %s, %s", name, greetingConfig.get(EVENING_MESSAGE)); + } else { + return String.format("Hello %s, %s", name, greetingConfig.get(NIGHT_MESSAGE)); + } + } + + public String greet() { + return greet(LocalDateTime.now()); + } + +} diff --git a/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/GreeterConfigParams.java b/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/GreeterConfigParams.java new file mode 100644 index 0000000000..fa30b0f312 --- /dev/null +++ b/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/GreeterConfigParams.java @@ -0,0 +1,11 @@ +package com.baeldung.greeter; + +public class GreeterConfigParams { + + public static final String USER_NAME = "user.name"; + public static final String MORNING_MESSAGE = "morning.message"; + public static final String AFTERNOON_MESSAGE = "afternoon.message"; + public static final String EVENING_MESSAGE = "evening.message"; + public static final String NIGHT_MESSAGE = "night.message"; + +} diff --git a/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/GreetingConfig.java b/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/GreetingConfig.java new file mode 100644 index 0000000000..fbbe11cf4f --- /dev/null +++ b/spring-boot-custom-starter/greeter/src/main/java/com/baeldung/greeter/GreetingConfig.java @@ -0,0 +1,9 @@ +package com.baeldung.greeter; + +import java.util.Properties; + +public class GreetingConfig extends Properties{ + + private static final long serialVersionUID = 5662570853707247891L; + +} diff --git a/spring-boot-custom-starter/greeter/src/test/java/com/baeldung/greeter/GreeterTest.java b/spring-boot-custom-starter/greeter/src/test/java/com/baeldung/greeter/GreeterTest.java new file mode 100644 index 0000000000..834f1447bd --- /dev/null +++ b/spring-boot-custom-starter/greeter/src/test/java/com/baeldung/greeter/GreeterTest.java @@ -0,0 +1,56 @@ +package com.baeldung.greeter; + +import static com.baeldung.greeter.GreeterConfigParams.*; +import static org.junit.Assert.assertEquals; + +import java.time.LocalDateTime; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class GreeterTest { + + private static GreetingConfig greetingConfig; + + @BeforeClass + public static void initalizeGreetingConfig() { + greetingConfig = new GreetingConfig(); + greetingConfig.put(USER_NAME, "World"); + greetingConfig.put(MORNING_MESSAGE, "Good Morning"); + greetingConfig.put(AFTERNOON_MESSAGE, "Good Afternoon"); + greetingConfig.put(EVENING_MESSAGE, "Good Evening"); + greetingConfig.put(NIGHT_MESSAGE, "Good Night"); + } + + @Test + public void givenMorningTime_ifMorningMessage_thenSuccess() { + String expected = "Hello World, Good Morning"; + Greeter greeter = new Greeter(greetingConfig); + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 6, 0)); + assertEquals(expected, actual); + } + + @Test + public void givenAfternoonTime_ifAfternoonMessage_thenSuccess() { + String expected = "Hello World, Good Afternoon"; + Greeter greeter = new Greeter(greetingConfig); + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 13, 0)); + assertEquals(expected, actual); + } + + @Test + public void givenEveningTime_ifEveningMessage_thenSuccess() { + String expected = "Hello World, Good Evening"; + Greeter greeter = new Greeter(greetingConfig); + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 19, 0)); + assertEquals(expected, actual); + } + + @Test + public void givenNightTime_ifNightMessage_thenSuccess() { + String expected = "Hello World, Good Night"; + Greeter greeter = new Greeter(greetingConfig); + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 21, 0)); + assertEquals(expected, actual); + } +} diff --git a/spring-boot-custom-starter/pom.xml b/spring-boot-custom-starter/pom.xml new file mode 100644 index 0000000000..e24ff071d4 --- /dev/null +++ b/spring-boot-custom-starter/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + com.baeldung + spring-boot-custom-starter + 0.0.1-SNAPSHOT + pom + + + UTF-8 + + + + greeter + greeter-spring-boot-autoconfigure + greeter-spring-boot-starter + greeter-spring-boot-sample-app + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/spring-boot/README.MD b/spring-boot/README.MD index bb15ffc8cc..dfd1327781 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -18,3 +18,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Create a Custom FailureAnalyzer with Spring Boot](http://www.baeldung.com/spring-boot-failure-analyzer) - [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source) - [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation) +- [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom) +- [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 5f77be43e3..b00af7fc94 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -119,6 +119,12 @@ ${tomee-servlet-api.version} provided + + + mysql + mysql-connector-java + 6.0.6 + @@ -165,6 +171,7 @@ **/*IntegrationTest.java **/*LiveTest.java + **/AutoconfigurationTest.java @@ -190,6 +197,7 @@ **/*LiveTest.java + **/AutoconfigurationTest.java **/*IntegrationTest.java @@ -206,6 +214,39 @@
+ + autoconfiguration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/*IntegrationTest.java + + + **/AutoconfigurationTest.java + + + + + + + json + + + + + + diff --git a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java index b4d416dd96..d54fa5a7c1 100644 --- a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java +++ b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java @@ -4,6 +4,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + /** * using the following annotations are equivalent: * */ -@SpringBootApplication +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) @ServletComponentScan("com.baeldung.annotation.servletcomponentscan.components") public class SpringBootAnnotatedApp { diff --git a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java index 8a39078aac..44030f440b 100644 --- a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java +++ b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java @@ -3,7 +3,9 @@ package com.baeldung.annotation.servletcomponentscan; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) @ComponentScan(basePackages = "com.baeldung.annotation.servletcomponentscan.components") public class SpringBootPlainApp { diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java b/spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java new file mode 100644 index 0000000000..09f387902d --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java @@ -0,0 +1,113 @@ +package com.baeldung.autoconfiguration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureOrder; +import org.springframework.boot.autoconfigure.condition.*; +import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; +import org.springframework.context.annotation.*; +import org.springframework.core.Ordered; +import org.springframework.core.env.Environment; +import org.springframework.core.type.AnnotatedTypeMetadata; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.util.ClassUtils; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Arrays; +import java.util.Properties; + +@Configuration +@ConditionalOnClass(DataSource.class) +@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) +@PropertySource("classpath:mysql.properties") +public class MySQLAutoconfiguration { + + @Autowired + private Environment env; + + @Bean + @ConditionalOnProperty(name = "usemysql", havingValue = "local") + @ConditionalOnMissingBean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://localhost:3306/myDb?createDatabaseIfNotExist=true"); + dataSource.setUsername("mysqluser"); + dataSource.setPassword("mysqlpass"); + + return dataSource; + } + + @Bean(name = "dataSource") + @ConditionalOnProperty(name = "usemysql", havingValue = "custom") + @ConditionalOnMissingBean + public DataSource dataSource2() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl(env.getProperty("mysql.url")); + dataSource.setUsername(env.getProperty("mysql.user") != null ? env.getProperty("mysql.user") : ""); + dataSource.setPassword(env.getProperty("mysql.pass") != null ? env.getProperty("mysql.pass") : ""); + + return dataSource; + } + + @Bean + @ConditionalOnBean(name = "dataSource") + @ConditionalOnMissingBean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan("com.baeldung.autoconfiguration.example"); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + if (additionalProperties() != null) { + em.setJpaProperties(additionalProperties()); + } + return em; + } + + @Bean + @ConditionalOnMissingBean(type = "JpaTransactionManager") + JpaTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory); + return transactionManager; + } + + @ConditionalOnResource(resources = "classpath:mysql.properties") + @Conditional(HibernateCondition.class) + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("mysql-hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("mysql-hibernate.dialect")); + hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("mysql-hibernate.show_sql") != null ? env.getProperty("mysql-hibernate.show_sql") : "false"); + + return hibernateProperties; + } + + static class HibernateCondition extends SpringBootCondition { + + private static final String[] CLASS_NAMES = { + "org.hibernate.ejb.HibernateEntityManager", + "org.hibernate.jpa.HibernateEntityManager" }; + + @Override + public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { + ConditionMessage.Builder message = ConditionMessage.forCondition("Hibernate"); + + return Arrays.stream(CLASS_NAMES) + .filter(className -> ClassUtils.isPresent(className, context.getClassLoader())) + .map(className -> ConditionOutcome + .match(message.found("class").items(Style.NORMAL, className))) + .findAny() + .orElseGet(() -> ConditionOutcome + .noMatch(message.didNotFind("class", "classes").items(Style.NORMAL, Arrays.asList(CLASS_NAMES)))); + } + + } +} diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java b/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java new file mode 100644 index 0000000000..f419dbf4fd --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.autoconfiguration.example; + +import javax.annotation.security.RolesAllowed; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AutoconfigurationApplication { + @RolesAllowed("*") + public static void main(String[] args) { + System.setProperty("security.basic.enabled", "false"); + SpringApplication.run(AutoconfigurationApplication.class, args); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java b/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java new file mode 100644 index 0000000000..31ce0fd969 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java @@ -0,0 +1,27 @@ +package com.baeldung.autoconfiguration.example; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class MyUser { + @Id + private String email; + + public MyUser() { + } + + public MyUser(String email) { + super(); + this.email = email; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java b/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java new file mode 100644 index 0000000000..fa411bc0b8 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.autoconfiguration.example; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MyUserRepository extends JpaRepository{ + +} diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java index 81345eac83..c12c28d00a 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java @@ -2,6 +2,7 @@ package com.baeldung.dynamicvalidation; import com.baeldung.dynamicvalidation.dao.ContactInfoExpressionRepository; import com.baeldung.dynamicvalidation.model.ContactInfoExpression; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.thymeleaf.util.StringUtils; @@ -12,27 +13,34 @@ import java.util.regex.Pattern; public class ContactInfoValidator implements ConstraintValidator { + private static final Logger LOG = Logger.getLogger(ContactInfoValidator.class); + @Autowired private ContactInfoExpressionRepository expressionRepository; @Value("${contactInfoType}") String expressionType; + private String pattern; + @Override public void initialize(final ContactInfo contactInfo) { + if (StringUtils.isEmptyOrWhitespace(expressionType)) { + LOG.error("Contact info type missing!"); + } else { + pattern = expressionRepository.findOne(expressionType) + .map(ContactInfoExpression::getPattern) + .orElse(""); + } } @Override public boolean isValid(final String value, final ConstraintValidatorContext context) { - if (StringUtils.isEmptyOrWhitespace(expressionType)) { - return false; + if (!StringUtils.isEmptyOrWhitespace(pattern)) { + return Pattern.matches(pattern, value); } - - return expressionRepository - .findOne(expressionType) - .map(ContactInfoExpression::getPattern) - .map(p -> Pattern.matches(p, value)) - .orElse(false); + LOG.error("Contact info pattern missing!"); + return false; } } diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java index d1e6b845d7..f08271f307 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/CustomerController.java @@ -1,10 +1,7 @@ package com.baeldung.dynamicvalidation.config; -import java.util.List; - import javax.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java index 0eeac2a8dc..d89dfc5fcd 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/config/PersistenceConfig.java @@ -6,7 +6,6 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -16,11 +15,6 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @Configuration public class PersistenceConfig { - @Bean - public JdbcTemplate getJdbcTemplate() { - return new JdbcTemplate(dataSource()); - } - @Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java index f043458fce..78d3580793 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/model/Customer.java @@ -4,6 +4,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.validation.constraints.NotNull; import com.baeldung.dynamicvalidation.ContactInfo; @@ -15,6 +16,7 @@ public class Customer { private long id; @ContactInfo + @NotNull private String contactInfo; public Customer() { diff --git a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java index 3489732b6f..9d379cbc09 100644 --- a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java +++ b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java @@ -5,7 +5,9 @@ import javax.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class FailureAnalyzerApplication { @RolesAllowed("*") public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java index cd696eae70..c077692edb 100644 --- a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java +++ b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java @@ -6,7 +6,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.io.ClassPathResource; -@SpringBootApplication(scanBasePackages = { "com.baeldung.git" }) +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(scanBasePackages = { "com.baeldung.git" }, exclude=MySQLAutoconfiguration.class) public class CommitIdApplication { public static void main(String[] args) { SpringApplication.run(CommitIdApplication.class, args); diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java index c92d1c32e6..b743eb4b61 100644 --- a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java +++ b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java @@ -5,7 +5,9 @@ import javax.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class InternationalizationApp { @RolesAllowed("*") public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/intro/App.java b/spring-boot/src/main/java/com/baeldung/intro/App.java index 30e1c2b5ba..9553d814ac 100644 --- a/spring-boot/src/main/java/com/baeldung/intro/App.java +++ b/spring-boot/src/main/java/com/baeldung/intro/App.java @@ -3,7 +3,9 @@ package com.baeldung.intro; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class App { public static void main( String[] args ) diff --git a/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java b/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java index a6ea3757fe..8965e2f013 100644 --- a/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java +++ b/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java @@ -5,7 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class ApplicationMain extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/utils/Application.java b/spring-boot/src/main/java/com/baeldung/utils/Application.java index a3d9f9130c..9d5d75bce2 100644 --- a/spring-boot/src/main/java/com/baeldung/utils/Application.java +++ b/spring-boot/src/main/java/com/baeldung/utils/Application.java @@ -6,7 +6,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) @ComponentScan(basePackages="com.baeldung.utils") public class Application { diff --git a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java index d2135754c9..44d48f5f8f 100644 --- a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java +++ b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java @@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class WebjarsdemoApplication { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/org/baeldung/Application.java b/spring-boot/src/main/java/org/baeldung/Application.java index aae0c427a9..c47bb90830 100644 --- a/spring-boot/src/main/java/org/baeldung/Application.java +++ b/spring-boot/src/main/java/org/baeldung/Application.java @@ -3,7 +3,9 @@ package org.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.context.ApplicationContext; -@org.springframework.boot.autoconfigure.SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@org.springframework.boot.autoconfigure.SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class Application { private static ApplicationContext applicationContext; diff --git a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java index e61d140396..2d83b650ec 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java +++ b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java @@ -3,7 +3,9 @@ package org.baeldung.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class DemoApplication { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java index 8442fc03a3..1bfde0f0bd 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java @@ -5,9 +5,10 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @@ -15,16 +16,16 @@ import org.springframework.web.bind.annotation.RestController; public class EmployeeRestController { @Autowired - EmployeeService employeeService; + private EmployeeService employeeService; - @RequestMapping(value = "/employees", method = RequestMethod.POST) + @PostMapping("/employees") public ResponseEntity createEmployee(@RequestBody Employee employee) { HttpStatus status = HttpStatus.CREATED; Employee saved = employeeService.save(employee); return new ResponseEntity<>(saved, status); } - @RequestMapping(value = "/employees", method = RequestMethod.GET) + @GetMapping("/employees") public List getAllEmployees() { return employeeService.getAllEmployees(); } diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java index 21936255e0..6d5bf426ec 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java @@ -13,7 +13,7 @@ import org.springframework.stereotype.Service; public class EmployeeServiceImpl implements EmployeeService { @Autowired - EmployeeRepository employeeRepository; + private EmployeeRepository employeeRepository; @Override public Optional getEmployeeById(Long id) { diff --git a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java index 582d2d9e9c..872426d850 100644 --- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java +++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java @@ -14,11 +14,13 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @RestController -@EnableAutoConfiguration +@EnableAutoConfiguration(exclude=MySQLAutoconfiguration.class) @ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service" }) public class SpringBootApplication { diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java index 23d741b98c..9f8dadbe55 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java @@ -7,8 +7,10 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean; +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + @EntityScan(basePackageClasses = Foo.class) -@SpringBootApplication +@SpringBootApplication(exclude=MySQLAutoconfiguration.class) public class Application { public static void main(String[] args) { System.setProperty("spring.config.name", "exception"); diff --git a/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot/src/main/resources/META-INF/spring.factories index e3d3aa4c8e..5f55544eff 100644 --- a/spring-boot/src/main/resources/META-INF/spring.factories +++ b/spring-boot/src/main/resources/META-INF/spring.factories @@ -1 +1,3 @@ -org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer \ No newline at end of file +org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfiguration.MySQLAutoconfiguration \ No newline at end of file diff --git a/spring-boot/src/main/resources/mysql.properties b/spring-boot/src/main/resources/mysql.properties new file mode 100644 index 0000000000..27092f852f --- /dev/null +++ b/spring-boot/src/main/resources/mysql.properties @@ -0,0 +1,5 @@ +usemysql=local + +mysql-hibernate.dialect=org.hibernate.dialect.MySQLDialect +mysql-hibernate.show_sql=true +mysql-hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationTest.java b/spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationTest.java new file mode 100644 index 0000000000..608d0d10bc --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.autoconfiguration; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.autoconfiguration.example.AutoconfigurationApplication; +import com.baeldung.autoconfiguration.example.MyUser; +import com.baeldung.autoconfiguration.example.MyUserRepository; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = AutoconfigurationApplication.class) +@EnableJpaRepositories(basePackages = { "com.baeldung.autoconfiguration.example" }) +public class AutoconfigurationTest { + + @Autowired + private MyUserRepository userRepository; + + @Test + public void whenSaveUser_thenOk() { + MyUser user = new MyUser("user@email.com"); + userRepository.save(user); + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeControllerIntegrationTest.java similarity index 91% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java rename to spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeControllerIntegrationTest.java index 0187ba9969..2146fc09bc 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeControllerIntegrationTest.java @@ -1,21 +1,5 @@ package org.baeldung.boot.boottest; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.hasSize; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.util.Arrays; -import java.util.List; - -import org.baeldung.boot.boottest.Employee; -import org.baeldung.boot.boottest.EmployeeRestController; -import org.baeldung.boot.boottest.EmployeeService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,15 +12,28 @@ import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + @RunWith(SpringRunner.class) @WebMvcTest(EmployeeRestController.class) -public class EmployeeRestControllerTest { +public class EmployeeControllerIntegrationTest { @Autowired - MockMvc mvc; + private MockMvc mvc; @MockBean - EmployeeService service; + private EmployeeService service; @Before public void setUp() throws Exception { diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java similarity index 94% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java rename to spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java index f47e28a7e1..cf94f4be49 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java @@ -17,13 +17,13 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @DataJpaTest -public class EmployeeRepositoryTest { +public class EmployeeRepositoryIntegrationTest { @Autowired - TestEntityManager entityManager; + private TestEntityManager entityManager; @Autowired - EmployeeRepository employeeRepository; + private EmployeeRepository employeeRepository; @Test public void whenFindByName_thenReturnEmployee() { diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntegrationTest.java similarity index 96% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java rename to spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntegrationTest.java index 6360970345..110092d293 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntegrationTest.java @@ -31,13 +31,13 @@ import org.springframework.test.web.servlet.MockMvc; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = DemoApplication.class) @AutoConfigureMockMvc @TestPropertySource(locations = "classpath:application-integrationtest.properties") -public class EmployeeRestControllerIntTest { +public class EmployeeRestControllerIntegrationTest { @Autowired - MockMvc mvc; + private MockMvc mvc; @Autowired - EmployeeRepository repository; + private EmployeeRepository repository; @After public void resetDb() { diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java similarity index 96% rename from spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java rename to spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java index 345cc29e02..e8a585a23e 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java @@ -23,7 +23,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -public class EmployeeServiceImplTest { +public class EmployeeServiceImplIntegrationTest { @TestConfiguration static class EmployeeServiceImplTestContextConfiguration { @@ -34,10 +34,10 @@ public class EmployeeServiceImplTest { } @Autowired - EmployeeService employeeService; + private EmployeeService employeeService; @MockBean - EmployeeRepository employeeRepository; + private EmployeeRepository employeeRepository; @Before public void setUp() { diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml b/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml index de76c86a24..78a0e05b77 100644 --- a/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml @@ -24,6 +24,12 @@ org.springframework.cloud spring-cloud-starter-zookeeper-discovery 1.0.3.RELEASE + + + commons-logging + commons-logging + + org.springframework.boot diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml index 1c829a50df..00af49eaa8 100644 --- a/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml @@ -24,6 +24,12 @@ org.springframework.cloud spring-cloud-starter-zookeeper-discovery 1.0.3.RELEASE + + + commons-logging + commons-logging + + diff --git a/spring-core/README.md b/spring-core/README.md index a32d30939f..3f2abe42a1 100644 --- a/spring-core/README.md +++ b/spring-core/README.md @@ -4,3 +4,4 @@ - [How to use the Spring FactoryBean?](http://www.baeldung.com/spring-factorybean) - [Constructor Dependency Injection in Spring](http://www.baeldung.com/constructor-injection-in-spring) - [Constructor Injection in Spring with Lombok](http://www.baeldung.com/spring-injection-lombok) +- [A Quick Guide to Spring @Value](http://www.baeldung.com/spring-value-annotation) diff --git a/spring-core/pom.xml b/spring-core/pom.xml index 3b423104d7..175a9b64d1 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -24,7 +24,7 @@ org.springframework spring-core - ${spring.version} + ${spring.version} org.springframework diff --git a/spring-core/src/main/java/com/baeldung/value/ValuesApp.java b/spring-core/src/main/java/com/baeldung/value/ValuesApp.java index 25f4b9fb9c..f525dfde89 100644 --- a/spring-core/src/main/java/com/baeldung/value/ValuesApp.java +++ b/spring-core/src/main/java/com/baeldung/value/ValuesApp.java @@ -1,5 +1,6 @@ package com.baeldung.value; +import java.util.Arrays; import java.util.List; import javax.annotation.PostConstruct; @@ -30,6 +31,9 @@ public class ValuesApp { @Value("${priority}") private String prioritySystemProperty; + @Value("${listOfValues}") + private String[] valuesArray; + @Value("#{systemProperties['priority']}") private String spelValue; @@ -60,6 +64,7 @@ public class ValuesApp { System.out.println(systemValue); System.out.println(someDefault); System.out.println(prioritySystemProperty); + System.out.println(Arrays.toString(valuesArray)); System.out.println(spelValue); System.out.println(spelSomeDefault); System.out.println(someBeanValue); diff --git a/spring-data-cassandra/pom.xml b/spring-data-cassandra/pom.xml index ef664fef79..49a222e93d 100644 --- a/spring-data-cassandra/pom.xml +++ b/spring-data-cassandra/pom.xml @@ -37,6 +37,12 @@ org.springframework spring-core ${org.springframework.version} + + + commons-logging + commons-logging + + junit @@ -72,6 +78,12 @@ org.hectorclient hector-core ${hector-core.version} + + + commons-logging + commons-logging + + com.datastax.cassandra @@ -94,11 +106,6 @@ jcl-over-slf4j ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-data-couchbase-2/pom.xml b/spring-data-couchbase-2/pom.xml index 9284234638..26a9ffcf2d 100644 --- a/spring-data-couchbase-2/pom.xml +++ b/spring-data-couchbase-2/pom.xml @@ -14,6 +14,12 @@ org.springframework spring-context ${spring-framework.version} + + + commons-logging + commons-logging + + org.springframework @@ -56,11 +62,6 @@ jcl-over-slf4j ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-data-dynamodb/pom.xml b/spring-data-dynamodb/pom.xml index 8b06c0b36f..3216318665 100644 --- a/spring-data-dynamodb/pom.xml +++ b/spring-data-dynamodb/pom.xml @@ -94,6 +94,12 @@ com.amazonaws aws-java-sdk-dynamodb ${aws-java-sdk-dynamodb.version} + + + commons-logging + commons-logging + + com.github.derjust diff --git a/spring-data-elasticsearch/pom.xml b/spring-data-elasticsearch/pom.xml index b38a6a10bc..513a0a591b 100644 --- a/spring-data-elasticsearch/pom.xml +++ b/spring-data-elasticsearch/pom.xml @@ -30,6 +30,12 @@ org.springframework spring-core ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework.data @@ -71,11 +77,6 @@ jcl-over-slf4j ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - org.elasticsearch diff --git a/spring-data-gemfire/README.md b/spring-data-gemfire/README.md new file mode 100644 index 0000000000..78199e90d0 --- /dev/null +++ b/spring-data-gemfire/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [A Guide to GemFire with Spring Data](http://www.baeldung.com/spring-data-gemfire) diff --git a/spring-data-gemfire/pom.xml b/spring-data-gemfire/pom.xml index eb450ebc81..ab510bc2bc 100644 --- a/spring-data-gemfire/pom.xml +++ b/spring-data-gemfire/pom.xml @@ -60,6 +60,12 @@ org.springframework spring-context ${spring-context-version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index e5389c1d34..f5d7cf9eff 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -20,6 +20,12 @@ org.springframework spring-core ${org.springframework.version} + + + commons-logging + commons-logging + + @@ -68,12 +74,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - - com.querydsl querydsl-mongodb diff --git a/spring-data-neo4j/pom.xml b/spring-data-neo4j/pom.xml index 7df48498e5..6f08fe293b 100644 --- a/spring-data-neo4j/pom.xml +++ b/spring-data-neo4j/pom.xml @@ -35,6 +35,12 @@ org.springframework.data spring-data-neo4j ${spring-data-neo4j.version} + + + commons-logging + commons-logging + + @@ -70,6 +76,12 @@ neo4j-server ${neo4j.version} test-jar + + + commons-logging + commons-logging + + @@ -95,6 +107,12 @@ org.springframework spring-test ${spring-test.version} + + + commons-logging + commons-logging + + diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 9700dd7091..f006026c81 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -13,7 +13,6 @@ 1.7.5.RELEASE 3.2.4 2.9.0 - 1.2.17 4.12 0.10.0 2.19.1 @@ -32,12 +31,6 @@ ${cglib.version} - - log4j - log4j - ${log4j.version} - - redis.clients jedis @@ -49,6 +42,12 @@ org.springframework spring-core ${spring.version} + + + commons-logging + commons-logging + + diff --git a/spring-data-solr/pom.xml b/spring-data-solr/pom.xml index fd6c442abf..54fc0d3294 100644 --- a/spring-data-solr/pom.xml +++ b/spring-data-solr/pom.xml @@ -14,7 +14,6 @@ 4.3.4.RELEASE 2.19.1 2.0.5.RELEASE - 1.2.17 4.12 @@ -23,6 +22,12 @@ org.springframework spring-core ${spring.version} + + + commons-logging + commons-logging + + org.springframework.data @@ -34,11 +39,6 @@ spring-context ${spring.version} - - log4j - log4j - ${log4j.version} - junit junit diff --git a/spring-dispatcher-servlet/README.md b/spring-dispatcher-servlet/README.md new file mode 100644 index 0000000000..56bb353487 --- /dev/null +++ b/spring-dispatcher-servlet/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Spring DispatcherServlet](http://www.baeldung.com/spring-dispatcher-servlet) diff --git a/spring-dispatcher-servlet/pom.xml b/spring-dispatcher-servlet/pom.xml index 13ad062195..84a7a5b59d 100644 --- a/spring-dispatcher-servlet/pom.xml +++ b/spring-dispatcher-servlet/pom.xml @@ -1,100 +1,96 @@ - - + + 4.0.0 - + com.baeldung spring-dispatcher-servlet war - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - .. - - + 1.0.0 + spring-dispatcher-servlet + + 4.3.7.RELEASE + + + org.springframework + spring-core + ${springframework.version} + - javax.servlet - javax.servlet-api - ${javax.servlet.version} - provided + org.springframework + spring-web + ${springframework.version} org.springframework spring-webmvc - ${org.springframework.version} + ${springframework.version} - org.thymeleaf - thymeleaf-spring4 - ${thymeleaf.version} + javax.servlet + javax.servlet-api + 3.1.0 - org.slf4j - slf4j-api - ${org.slf4j.version} + javax.servlet.jsp.jstl + jstl-api + 1.2 - org.apache.logging.log4j - log4j-core - ${log4j.version} + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.1 - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} + org.codehaus.jackson + jackson-mapper-asl + 1.9.13 + + + javax.servlet + jstl + 1.2 + + + com.fasterxml.jackson.core + jackson-databind + 2.5.0 + + + commons-fileupload + commons-fileupload + 1.3 - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - false - - - - org.eclipse.jetty - jetty-maven-plugin - ${jetty-maven-plugin.version} - - - / - - - - + + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + org.apache.tomcat.maven + tomcat8-maven-plugin + 3.0-r1655215 + + /springdispatcherservlet + + + + org.apache.maven.plugins + maven-war-plugin + 3.0.0 + + src/main/webapp + false + + + + + springdispatcherservlet - - - - 4.3.4.RELEASE - 3.0.2.RELEASE - - - 1.7.21 - 2.7 - - - 3.1.0 - - - 3.6.0 - 3.0.0 - 9.3.14.v20161028 - - + \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/DispatcherServletApplication.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/DispatcherServletApplication.java deleted file mode 100644 index 181fb3f405..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/DispatcherServletApplication.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet; - -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -import javax.servlet.MultipartConfigElement; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -public class DispatcherServletApplication implements org.springframework.web.WebApplicationInitializer { - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - AnnotationConfigWebApplicationContext rootContext = - new AnnotationConfigWebApplicationContext(); - rootContext.register(RootConfiguration.class); - servletContext.addListener(new ContextLoaderListener(rootContext)); - AnnotationConfigWebApplicationContext webContext = - new AnnotationConfigWebApplicationContext(); - webContext.register(WebConfiguration.class); - DispatcherServlet dispatcherServlet = new DispatcherServlet(webContext); - ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", - dispatcherServlet); - servlet.addMapping("/*"); - MultipartConfigElement multipartConfigElement = - new MultipartConfigElement("/tmp"); - servlet.setMultipartConfig(multipartConfigElement); - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/RootConfiguration.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/RootConfiguration.java deleted file mode 100644 index 48281c5e5d..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/RootConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet; - -import com.baeldung.spring.dispatcher.servlet.models.Task; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.*; - -@Configuration -public class RootConfiguration { - @Bean - public Map> taskList() { - Map> taskMap = new HashMap<>(); - List taskList = new ArrayList<>(); - taskList.add(new Task("Clean the dishes!", new Date())); - taskMap.put("Cid", taskList); - return taskMap; - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/WebConfiguration.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/WebConfiguration.java deleted file mode 100644 index 419c1a2908..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/WebConfiguration.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet; - -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.ResourceBundleMessageSource; -import org.springframework.ui.context.support.ResourceBundleThemeSource; -import org.springframework.web.multipart.MultipartResolver; -import org.springframework.web.multipart.support.StandardServletMultipartResolver; -import org.springframework.web.servlet.HandlerExceptionResolver; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.ThemeResolver; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; -import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; -import org.springframework.web.servlet.theme.CookieThemeResolver; -import org.springframework.web.servlet.theme.ThemeChangeInterceptor; -import org.thymeleaf.spring4.SpringTemplateEngine; -import org.thymeleaf.spring4.view.ThymeleafViewResolver; -import org.thymeleaf.templatemode.TemplateMode; -import org.thymeleaf.templateresolver.ServletContextTemplateResolver; - -import javax.servlet.ServletContext; -import java.util.Locale; - -@Configuration -@ComponentScan("com.baeldung.spring.dispatcher.servlet.web") -@EnableWebMvc -public class WebConfiguration extends WebMvcConfigurerAdapter { - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry - .addResourceHandler("/public/**") - .addResourceLocations("/public/"); - } - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(localeChangeInterceptor()); - registry.addInterceptor(themeChangeInterceptor()); - } - - @Bean - public ServletContextTemplateResolver templateResolver(ServletContext servletContext) { - ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(servletContext); - templateResolver.setPrefix("/WEB-INF/views/"); - templateResolver.setSuffix(".html"); - templateResolver.setTemplateMode(TemplateMode.HTML); - return templateResolver; - } - - @Bean - public SpringTemplateEngine templateEngine(ServletContextTemplateResolver templateResolver) { - SpringTemplateEngine templateEngine = new SpringTemplateEngine(); - templateEngine.setTemplateResolver(templateResolver); - return templateEngine; - } - - @Bean - public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) { - ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); - viewResolver.setTemplateEngine(templateEngine); - return viewResolver; - } - - @Bean - public MessageSource messageSource() { - ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); - messageSource.setBasename("messages"); - messageSource.setFallbackToSystemLocale(false); - return messageSource; - } - - @Bean - public LocaleResolver localeResolver() { - CookieLocaleResolver localeResolver = new CookieLocaleResolver(); - localeResolver.setDefaultLocale(Locale.ENGLISH); - localeResolver.setCookieName("locale"); - localeResolver.setCookieMaxAge(-1); - return localeResolver; - } - - @Bean - public LocaleChangeInterceptor localeChangeInterceptor() { - LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); - localeChangeInterceptor.setParamName("lang"); - localeChangeInterceptor.setIgnoreInvalidLocale(true); - return localeChangeInterceptor; - } - - @Bean - public ResourceBundleThemeSource themeSource() { - ResourceBundleThemeSource themeSource = new ResourceBundleThemeSource(); - themeSource.setBasenamePrefix("theme-"); - themeSource.setFallbackToSystemLocale(false); - return themeSource; - } - - @Bean - public ThemeResolver themeResolver() { - CookieThemeResolver themeResolver = new CookieThemeResolver(); - themeResolver.setDefaultThemeName("robotask"); - themeResolver.setCookieName("theme"); - themeResolver.setCookieMaxAge(-1); - return themeResolver; - } - - @Bean - public ThemeChangeInterceptor themeChangeInterceptor() { - ThemeChangeInterceptor themeChangeInterceptor = new ThemeChangeInterceptor(); - themeChangeInterceptor.setParamName("theme"); - return themeChangeInterceptor; - } - - @Bean - public MultipartResolver multipartResolver() { - return new StandardServletMultipartResolver(); - } - - @Bean - public HandlerExceptionResolver handlerExceptionResolver() { - return new ExceptionHandlerExceptionResolver(); - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/models/Attachment.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/models/Attachment.java deleted file mode 100644 index 1d6248650f..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/models/Attachment.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.models; - -import java.util.UUID; - -public class Attachment { - private String id; - - private String name; - - private String description; - - public Attachment() { - this.id = UUID.randomUUID().toString(); - } - - public Attachment(String name, String description) { - this(); - this.name = name; - this.description = description; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Attachment that = (Attachment) o; - return id.equals(that.id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/models/Task.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/models/Task.java deleted file mode 100644 index 1e6a533e3a..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/models/Task.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.models; - -import org.springframework.format.annotation.DateTimeFormat; - -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -public class Task { - private String description; - - @DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm") - private Date due; - - private Set attachments = new HashSet<>(); - - public Task() { - } - - public Task(Date due) { - this.due = due; - } - - public Task(String description, Date due) { - this.description = description; - this.due = due; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Date getDue() { - return due; - } - - public void setDue(Date due) { - this.due = due; - } - - public Set getAttachments() { - return attachments; - } - - public void setAttachments(Set attachments) { - this.attachments = attachments; - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/AttachmentController.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/AttachmentController.java deleted file mode 100644 index 2521004ff1..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/AttachmentController.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import org.springframework.core.io.FileSystemResource; -import org.springframework.http.ResponseEntity; -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.RequestParam; - -@RequestMapping("/attachments") -public interface AttachmentController { - @GetMapping("/{attachmentId}") - ResponseEntity getAttachment( - @PathVariable("attachmentId") String attachmentId, - @RequestParam(name = "download", required = false, defaultValue = "false") boolean forcedDownload - ); -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/AttachmentControllerImpl.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/AttachmentControllerImpl.java deleted file mode 100644 index 75a15cf657..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/AttachmentControllerImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import com.baeldung.spring.dispatcher.servlet.models.Task; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.FileSystemResource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; - -import java.net.URLConnection; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -@Controller -public class AttachmentControllerImpl implements AttachmentController { - @Autowired - private Map> taskMap; - - @Override - public ResponseEntity getAttachment( - @PathVariable("attachmentId") String attachmentId, - @RequestParam(name = "download", required = false, defaultValue = "false") boolean forcedDownload - ) { - FileSystemResource resource = new FileSystemResource("/tmp/" + attachmentId); - HttpHeaders headers = new HttpHeaders(); - taskMap.values().stream() - .flatMap(Collection::stream) - .flatMap(t -> t.getAttachments().stream()) - .filter(a -> a.getId().equals(attachmentId)) - .findFirst() - .ifPresent(a -> { - headers.add("Content-Disposition", - "attachment; filename=" + a.getName()); - headers.add("Content-Type", forcedDownload ? - MediaType.APPLICATION_OCTET_STREAM_VALUE : - URLConnection.guessContentTypeFromName(a.getName())); - }); - return new ResponseEntity<>(resource, headers, HttpStatus.OK); - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/GlobalDefaultExceptionHandler.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/GlobalDefaultExceptionHandler.java deleted file mode 100644 index f25eb601a7..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/GlobalDefaultExceptionHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice -public class GlobalDefaultExceptionHandler { - @ExceptionHandler(Exception.class) - public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) throws Exception { - ModelAndView modelAndView = new ModelAndView(); - modelAndView.addObject("exception", e); - modelAndView.addObject("url", request.getRequestURL()); - modelAndView.setViewName("error"); - return modelAndView; - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/HomeController.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/HomeController.java deleted file mode 100644 index 5ac39fadb4..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/HomeController.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -@RequestMapping("/") -public interface HomeController { - @GetMapping("/*") - String home( - Model model - ); -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/HomeControllerImpl.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/HomeControllerImpl.java deleted file mode 100644 index 66d869ca67..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/HomeControllerImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import com.baeldung.spring.dispatcher.servlet.models.Task; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Controller -public class HomeControllerImpl implements HomeController { - @Autowired - private Map> taskMap; - - @Override - public String home(Model model) { - List users = taskMap.keySet().stream() - .sorted() - .collect(Collectors.toList()); - model.addAttribute("users", users); - return "home"; - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/TaskController.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/TaskController.java deleted file mode 100644 index eff93ffb2f..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/TaskController.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import com.baeldung.spring.dispatcher.servlet.models.Task; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -@RequestMapping("/tasks") -public interface TaskController { - @GetMapping("/{username}/list") - String listTasks( - @PathVariable("username") String username, - Model model - ); - - @GetMapping("/{username}/add") - String addTask( - @PathVariable("username") String username, - Model model - ); - - @PostMapping("/{username}/add") - String addTask( - @PathVariable("username") String username, - @ModelAttribute Task task - ); - - @GetMapping("/{username}/get/{id}") - String getTask( - @PathVariable("username") String username, - @PathVariable("id") int id, - Model model - ); - - @GetMapping("/{username}/get/{id}/attach") - String attachToTask( - @PathVariable("username") String username, - @PathVariable("id") int id, - Model model - ); - - @PostMapping("/{username}/get/{id}/attach") - String attachToTask( - @PathVariable("username") String username, - @PathVariable("id") int id, - @RequestParam("attachment") MultipartFile attachment, - @RequestParam("description") String description - ); -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/TaskControllerImpl.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/TaskControllerImpl.java deleted file mode 100644 index 464e58aa54..0000000000 --- a/spring-dispatcher-servlet/src/main/java/com/baeldung/spring/dispatcher/servlet/web/TaskControllerImpl.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.baeldung.spring.dispatcher.servlet.web; - -import com.baeldung.spring.dispatcher.servlet.models.Attachment; -import com.baeldung.spring.dispatcher.servlet.models.Task; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; -import java.util.stream.Collectors; - -@Controller -public class TaskControllerImpl implements TaskController { - @Autowired - private Map> taskMap; - - @Override - public String listTasks( - @PathVariable("username") String username, - Model model - ) { - List tasks = taskMap.get(username).stream() - .sorted(Comparator.comparing(Task::getDue)) - .collect(Collectors.toList()); - model.addAttribute("username", username); - model.addAttribute("tasks", tasks); - return "task-list"; - } - - @Override - public String addTask( - @PathVariable("username") String username, - Model model - ) { - model.addAttribute("username", username); - model.addAttribute("task", new Task(new Date())); - return "task-add"; - } - - @Override - public String addTask( - @PathVariable("username") String username, - @ModelAttribute Task task - ) { - List taskList = taskMap.get(username); - if (taskList == null) { - taskList = new ArrayList<>(); - } - taskList.add(task); - taskMap.put(username, taskList); - return "redirect:list"; - } - - @Override - public String getTask( - @PathVariable("username") String username, - @PathVariable("id") int id, - Model model - ) { - Task task = taskMap.get(username).get(id); - model.addAttribute("username", username); - model.addAttribute("id", id); - model.addAttribute("task", task); - return "task-get"; - } - - @Override - public String attachToTask( - @PathVariable("username") String username, - @PathVariable("id") int id, - Model model - ) { - model.addAttribute("username", username); - model.addAttribute("id", id); - return "task-attach"; - } - - @Override - public String attachToTask( - @PathVariable("username") String username, - @PathVariable("id") int id, - @RequestParam("attachment") MultipartFile multipartFile, - @RequestParam("description") String description - ) { - Task task = taskMap.get(username).get(id); - Attachment attachment = new Attachment(multipartFile.getOriginalFilename(), - description); - task.getAttachments().add(attachment); - try (InputStream inputStream = - new BufferedInputStream(multipartFile.getInputStream()); - OutputStream outputStream = - new BufferedOutputStream(Files.newOutputStream( - Paths.get("/tmp", attachment.getId())))) { - byte[] buf = new byte[1024 * 16]; - int len; - while ((len = inputStream.read(buf)) != -1) { - outputStream.write(buf, 0, len); - } - } catch (IOException e) { - throw new RuntimeException("Failed to upload file!", e); - } - return "redirect:./"; - } -} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java new file mode 100644 index 0000000000..f5ad032e84 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/AppConfig.java @@ -0,0 +1,83 @@ +package com.baeldung.springdispatcherservlet.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.ui.context.support.ResourceBundleThemeSource; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; +import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.resource.PathResourceResolver; +import org.springframework.web.servlet.theme.CookieThemeResolver; +import org.springframework.web.servlet.theme.ThemeChangeInterceptor; +import org.springframework.web.servlet.view.JstlView; +import org.springframework.web.servlet.view.UrlBasedViewResolver; + +import java.io.IOException; + +@Configuration +@EnableWebMvc +@ComponentScan("com.baeldung.springdispatcherservlet") +public class AppConfig extends WebMvcConfigurerAdapter { + + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("index"); + } + + /** Multipart file uploading configuratioin */ + @Bean + public CommonsMultipartResolver multipartResolver() throws IOException { + CommonsMultipartResolver resolver = new CommonsMultipartResolver(); + resolver.setMaxUploadSize(10000000); + return resolver; + } + + /** View resolver for JSP */ + @Bean + public UrlBasedViewResolver viewResolver() { + UrlBasedViewResolver resolver = new UrlBasedViewResolver(); + resolver.setPrefix("/WEB-INF/jsp/"); + resolver.setSuffix(".jsp"); + resolver.setViewClass(JstlView.class); + return resolver; + } + + /** Static resource locations including themes*/ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**/*") + .addResourceLocations("/", "/resources/") + .setCachePeriod(3600) + .resourceChain(true) + .addResolver(new PathResourceResolver()); + } + + /** BEGIN theme configuration */ + @Bean + public ResourceBundleThemeSource themeSource(){ + ResourceBundleThemeSource themeSource = new ResourceBundleThemeSource(); + themeSource.setDefaultEncoding("UTF-8"); + themeSource.setBasenamePrefix("themes."); + return themeSource; + } + + @Bean + public CookieThemeResolver themeResolver(){ + CookieThemeResolver resolver = new CookieThemeResolver(); + resolver.setDefaultThemeName("default"); + resolver.setCookieName("example-theme-cookie"); + return resolver; + } + + @Bean + public ThemeChangeInterceptor themeChangeInterceptor(){ + ThemeChangeInterceptor interceptor = new ThemeChangeInterceptor(); + interceptor.setParamName("theme"); + return interceptor; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(themeChangeInterceptor()); + } + /** END theme configuration */ +} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java new file mode 100644 index 0000000000..0c6c7141a7 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/configuration/WebAppInitializer.java @@ -0,0 +1,23 @@ +package com.baeldung.springdispatcherservlet.configuration; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class WebAppInitializer implements WebApplicationInitializer { + + @Override + public void onStartup(ServletContext container) throws ServletException { + AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); + context.register(AppConfig.class); + context.setServletContext(container); + + ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(context)); + servlet.setLoadOnStartup(1); + servlet.addMapping("/"); + } +} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/MultipartController.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/MultipartController.java new file mode 100644 index 0000000000..1cc8261f7c --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/MultipartController.java @@ -0,0 +1,41 @@ +package com.baeldung.springdispatcherservlet.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.ServletContext; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; + +@Controller +public class MultipartController { + + @Autowired + ServletContext context; + + @RequestMapping(value = "/upload", method = RequestMethod.POST) + public ModelAndView FileuploadController(@RequestParam("file") MultipartFile file) { + ModelAndView modelAndView = new ModelAndView("index"); + try { + InputStream in = file.getInputStream(); + String path = new File(".").getAbsolutePath(); + FileOutputStream f = new FileOutputStream(path.substring(0, path.length()-1)+ "/uploads/" + file.getOriginalFilename()); + int ch; + while ((ch = in.read()) != -1) { + f.write(ch); + } + f.flush(); + f.close(); + modelAndView.getModel().put("message", "File uploaded successfully!"); + } catch (Exception e) { + System.out.println("Exception uploading multipart: " + e); + } + return modelAndView; + } +} diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserController.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserController.java new file mode 100644 index 0000000000..16e6f293ec --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserController.java @@ -0,0 +1,30 @@ +package com.baeldung.springdispatcherservlet.controller; + +import com.baeldung.springdispatcherservlet.domain.User; +import com.baeldung.springdispatcherservlet.services.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/user") +public class UserController { + + @Autowired + private UserService userService; + + @RequestMapping(value = "/example", method = RequestMethod.GET) + @ResponseBody + public User fetchUserExample() { + return userService.exampleUser(); + } + + @RequestMapping(value = "/name", method = RequestMethod.GET) + @ResponseBody + public User fetchUserByFirstName(@RequestParam(value = "firstName") String firstName) { + return userService.fetchUserByFirstName(firstName); + } +} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserRestController.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserRestController.java new file mode 100644 index 0000000000..9052662f17 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/controller/UserRestController.java @@ -0,0 +1,27 @@ +package com.baeldung.springdispatcherservlet.controller; + +import com.baeldung.springdispatcherservlet.domain.User; +import com.baeldung.springdispatcherservlet.services.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/rest/user") +public class UserRestController { + + @Autowired + private UserService userService; + + @RequestMapping(value = "/example", method = RequestMethod.GET) + public User fetchUserExample() { + return userService.exampleUser(); + } + + @RequestMapping(value = "/name", method = RequestMethod.GET) + public User fetchUserByFirstName(@RequestParam(value = "firstName") String firstName) { + return userService.fetchUserByFirstName(firstName); + } +} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain/User.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain/User.java new file mode 100644 index 0000000000..6e8cde50db --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/domain/User.java @@ -0,0 +1,41 @@ +package com.baeldung.springdispatcherservlet.domain; + + +public class User { + private long id; + private String firstName; + private String lastName; + + public User(long id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public User() { + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/services/UserService.java b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/services/UserService.java new file mode 100644 index 0000000000..1b9bdd4a71 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/java/com/baeldung/springdispatcherservlet/services/UserService.java @@ -0,0 +1,17 @@ +package com.baeldung.springdispatcherservlet.services; + +import org.springframework.stereotype.Service; + +import com.baeldung.springdispatcherservlet.domain.User; + +@Service +public class UserService { + + public User fetchUserByFirstName(String firstName) { + return new User(1, firstName, "Everyperson"); + } + + public User exampleUser() { + return new User(1, "Example", "Everyperson"); + } +} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/resources/README.md b/spring-dispatcher-servlet/src/main/resources/README.md deleted file mode 100644 index 7c97e75a2c..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Info ## - -- The diagram is created with [yed](http://www.yworks.com/products/yed) diff --git a/spring-dispatcher-servlet/src/main/resources/diagram.graphml b/spring-dispatcher-servlet/src/main/resources/diagram.graphml deleted file mode 100644 index 1806ab7719..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/diagram.graphml +++ /dev/null @@ -1,372 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - Servlet Engine (e.g. Tomcat) - - - - - - - - - - Folder 1 - - - - - - - - - - - - - - - - Controller - - - - - - - - - - - - - - - - - - - Model - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Model - - - - - - - - - - - - - - - - - - - - DispatcherServlet - - - - - - - - - - - - - - - - - - - View Template - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Return Control - - - - - - - - - - - - Render Response - - - - - - - - - - - - Delegate Request - - - - - - - - - - - - Delegate Rendering of Response - - - - - - - - - - - - - - - - - - - - - - - - - Incoming Request - - - - - - - - - - - - Return Response - - - - - - - - - - - - - - Handle Request - - - - - - - - - - - - - - Create Model - - - - - - - - - <?xml version="1.0" encoding="utf-8"?> -<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" - width="57px" height="67px" viewBox="0 0 57 67" enable-background="new 0 0 57 67" xml:space="preserve"> -<g> - - <radialGradient id="neck_x5F_white_1_" cx="28.0298" cy="-751.9429" r="11.4464" fx="25.7969" fy="-753.1596" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#B38E5D"/> - <stop offset="1" style="stop-color:#805126"/> - </radialGradient> - <path id="neck_x5F_white_2_" fill="url(#neck_x5F_white_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M19.278,37.799h18.188 - v13.23c-1.313,0.371-17.173,0.436-18.188,0.172V37.799z"/> - - <radialGradient id="SVGID_1_" cx="27.481" cy="-760.3003" r="31.0533" fx="21.4231" fy="-763.6011" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#B38E5D"/> - <stop offset="1" style="stop-color:#805126"/> - </radialGradient> - <path fill="url(#SVGID_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M49.529,51.225c-4.396-4.396-10.951-5.884-12.063-6.109 - V37.8H19.278c0,0,0.038,6.903,0,6.868c0,0-6.874,0.997-12.308,6.432C1.378,56.691,0.5,62.77,0.5,62.77 - c0,1.938,1.575,3.492,3.523,3.492h48.51c1.947,0,3.521-1.558,3.521-3.492C56.055,62.768,54.211,55.906,49.529,51.225z"/> - - <radialGradient id="face_x5F_white_1_" cx="27.7827" cy="-732.2632" r="23.424" fx="23.2131" fy="-734.753" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#B38E5D"/> - <stop offset="1" style="stop-color:#805126"/> - </radialGradient> - <path id="face_x5F_white_2_" fill="url(#face_x5F_white_1_)" stroke="#5B453B" stroke-miterlimit="10" d="M43.676,23.357 - c0.086,10.199-6.738,18.52-15.246,18.586c-8.503,0.068-15.467-8.146-15.553-18.344C12.794,13.4,19.618,5.079,28.123,5.012 - C36.627,4.945,43.59,13.158,43.676,23.357z"/> - - <linearGradient id="face_highlight_1_" gradientUnits="userSpaceOnUse" x1="2941.4297" y1="5674.7988" x2="2965.0596" y2="5768.2505" gradientTransform="matrix(0.275 0 0 0.2733 -783.3976 -1542.678)"> - <stop offset="0" style="stop-color:#FFFFFF;stop-opacity:0.42"/> - <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.12"/> - </linearGradient> - <path id="face_highlight_2_" fill="url(#face_highlight_1_)" d="M27.958,6.333c-6.035,0.047-10.747,4.493-12.787,10.386 - c-0.664,1.919-0.294,4.043,0.98,5.629c2.73,3.398,5.729,6.283,9.461,8.088c3.137,1.518,7.535,2.385,11.893,1.247 - c2.274-0.592,3.988-2.459,4.375-4.766c0.183-1.094,0.293-2.289,0.283-3.553C42.083,13.952,36.271,6.268,27.958,6.333z"/> - <path id="path9833_2_" fill="#4B4B4B" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" d="M28.372,0.5 - C17.537,0.5,8.269,7.748,9.153,26.125c0.563,6.563,5.862,12.042,9.366,13.531c-2.929-10.968-0.304-25.021-0.585-25.526 - c-0.281-0.505,3.536,6.728,3.536,6.728l3.183-8.312c5.541,4.28,0.393,11.309,1.049,11.058c4.26-1.631,5.34-9.228,5.34-9.228 - s2.729,3.657,2.701,5.504c-0.054,3.562,2.194-6.067,2.194-6.067l1.027,2.031c6.727,9.822,3.684,16.208,1.654,22.781 - c15.665-0.703,12.289-10.48,9.658-18.407C43.59,6.092,39.206,0.5,28.372,0.5z"/> - - <radialGradient id="collar_x5F_body_2_" cx="15.1587" cy="-763.7056" r="32.4004" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#B0E8FF"/> - <stop offset="1" style="stop-color:#74AEEE"/> - </radialGradient> - <path id="collar_x5F_body_1_" fill="url(#collar_x5F_body_2_)" stroke="#5491CF" d="M0.5,62.768c0,1.938,1.575,3.494,3.523,3.494 - h48.51c1.947,0,3.521-1.559,3.521-3.494c0,0-1.844-6.861-6.525-11.543c-4.815-4.813-11.244-6.146-11.244-6.146 - c-1.771,1.655-5.61,2.802-10.063,2.802c-4.453,0-8.292-1.146-10.063-2.802c0,0-5.755,0.586-11.189,6.021 - C1.378,56.689,0.5,62.768,0.5,62.768z"/> - - <radialGradient id="collar_x5F_r_2_" cx="31.5" cy="-753.832" r="9.2834" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#80CCFF"/> - <stop offset="1" style="stop-color:#74AEEE"/> - </radialGradient> - <path id="collar_x5F_r_1_" fill="url(#collar_x5F_r_2_)" stroke="#5491CF" d="M38.159,41.381c0,0-0.574,2.369-3.013,4.441 - c-2.108,1.795-5.783,2.072-5.783,2.072l3.974,6.217c0,0,2.957-1.637,5.009-3.848c1.922-2.072,1.37-5.479,1.37-5.479L38.159,41.381z - "/> - - <radialGradient id="collar_x5F_l_2_" cx="19.1377" cy="-753.873" r="9.2837" gradientTransform="matrix(1 0 0 -1 0.1201 -706.5371)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#80CCFF"/> - <stop offset="1" style="stop-color:#74AEEE"/> - </radialGradient> - <path id="collar_x5F_l_1_" fill="url(#collar_x5F_l_2_)" stroke="#5491CF" d="M18.63,41.422c0,0,0.576,2.369,3.012,4.441 - c2.109,1.793,5.785,2.072,5.785,2.072l-3.974,6.217c0,0-2.957-1.637-5.007-3.85c-1.922-2.072-1.37-5.48-1.37-5.48L18.63,41.422z"/> - - <radialGradient id="Knob2_2_" cx="27.8872" cy="9.9414" r="0.9669" gradientTransform="matrix(1 0 0 -1 0.04 66.1543)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#80CCFF"/> - <stop offset="1" style="stop-color:#74AEEE"/> - </radialGradient> - <circle id="Knob2_1_" fill="url(#Knob2_2_)" stroke="#5491CF" cx="28.258" cy="56.254" r="0.584"/> - - <radialGradient id="Knob1_2_" cx="27.9253" cy="3.6973" r="0.9669" gradientTransform="matrix(1 0 0 -1 0.04 66.1543)" gradientUnits="userSpaceOnUse"> - <stop offset="0" style="stop-color:#80CCFF"/> - <stop offset="1" style="stop-color:#74AEEE"/> - </radialGradient> - <circle id="Knob1_1_" fill="url(#Knob1_2_)" stroke="#5491CF" cx="28.296" cy="62.499" r="0.584"/> -</g> -</svg> - - - - diff --git a/spring-dispatcher-servlet/src/main/resources/diagram.png b/spring-dispatcher-servlet/src/main/resources/diagram.png deleted file mode 100644 index c0c545d680..0000000000 Binary files a/spring-dispatcher-servlet/src/main/resources/diagram.png and /dev/null differ diff --git a/spring-dispatcher-servlet/src/main/resources/log4j2.xml b/spring-dispatcher-servlet/src/main/resources/log4j2.xml deleted file mode 100644 index fb18e8279a..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/log4j2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-dispatcher-servlet/src/main/resources/messages.properties b/spring-dispatcher-servlet/src/main/resources/messages.properties deleted file mode 100644 index c36eb5aa42..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/messages.properties +++ /dev/null @@ -1,22 +0,0 @@ -home.title=Welcome to TaskTools! -task.add.description=description -task.add.due=due -task.add.header=Adding a task to {0}''s list: -task.add.submit=Submit -task.add.title={0}: task add -task.attach.attachment=attached file -task.attach.description=description -task.attach.header=task #{0}: attach file -task.attach.submit=Submit -task.attach.title=#{0}: Attach file -task.get.attach=Attach file -task.get.attachments=attachments: -task.get.download=Download -task.get.header=task #{0}: -task.get.list=Back -task.get.title={0}: task details -task.list.add-new=Add new -task.list.details=Details -task.list.header={0}''s tasks: -task.list.home=Home -task.list.title={0}: task list diff --git a/spring-dispatcher-servlet/src/main/resources/messages_de.properties b/spring-dispatcher-servlet/src/main/resources/messages_de.properties deleted file mode 100644 index 184b72101c..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/messages_de.properties +++ /dev/null @@ -1,22 +0,0 @@ -home.title=Willkommen bei TaskTools! -task.add.description=Beschreibung -task.add.due=f\u00e4llig -task.add.header=F\u00fcge eine Aufgabe zu {0}''s Liste hinzu: -task.add.submit=Senden -task.add.title={0}: Task hinzuf\u00fcgen -task.attach.attachment=Angeh\u00e4ngte Datei -task.attach.description=Beschreibung -task.attach.header=Task #{0}: Datei anh\u00e4ngen -task.attach.submit=Senden -task.attach.title=#{0}: Datei anh\u00e4ngen -task.get.attach=Datei anh\u00e4ngen -task.get.attachments=Anh\u00e4nge: -task.get.download=Download -task.get.header=Task #{0}: -task.get.list=Zur\u00fcck -task.get.title={0}: Task Details -task.list.add-new=Neuer Task -task.list.details=Details -task.list.header={0}''s Tasks: -task.list.home=Startseite -task.list.title={0}: Task Liste diff --git a/spring-dispatcher-servlet/src/main/resources/theme-post_it.properties b/spring-dispatcher-servlet/src/main/resources/theme-post_it.properties deleted file mode 100644 index d2998e2bdf..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/theme-post_it.properties +++ /dev/null @@ -1 +0,0 @@ -stylesheet=/public/css/themes/post_it.css diff --git a/spring-dispatcher-servlet/src/main/resources/theme-robotask.properties b/spring-dispatcher-servlet/src/main/resources/theme-robotask.properties deleted file mode 100644 index 68fe270b64..0000000000 --- a/spring-dispatcher-servlet/src/main/resources/theme-robotask.properties +++ /dev/null @@ -1 +0,0 @@ -stylesheet=/public/css/themes/robotask.css diff --git a/spring-dispatcher-servlet/src/main/resources/themes/default.properties b/spring-dispatcher-servlet/src/main/resources/themes/default.properties new file mode 100644 index 0000000000..a28d9bc939 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/resources/themes/default.properties @@ -0,0 +1 @@ +styleSheet=/resources/css/default.css \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/resources/themes/example.properties b/spring-dispatcher-servlet/src/main/resources/themes/example.properties new file mode 100644 index 0000000000..11e254eb58 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/resources/themes/example.properties @@ -0,0 +1 @@ +styleSheet=/resources/css/example.css \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp new file mode 100644 index 0000000000..c482eac361 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/jsp/index.jsp @@ -0,0 +1,30 @@ +<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + + + + + Spring Dispatcher + + + +

Hello World!

+
+ Switch Theme! + Switch Theme! +
+
+
+
+ + +
+
+
+ ${message} + + diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/error.html b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/error.html deleted file mode 100644 index 8f0f6afca7..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/error.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Error - - - - -

Error:

-

-

- - diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/home.html b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/home.html deleted file mode 100644 index 6adec7bb12..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/home.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - -

TaskTools

-
    -
  • - -
  • -
- - diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-add.html b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-add.html deleted file mode 100644 index 520486f52e..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-add.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - -

-
- - - -
- - diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-attach.html b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-attach.html deleted file mode 100644 index 23246f330b..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-attach.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - -

-
- - - -
- - diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-get.html b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-get.html deleted file mode 100644 index e7b35b6780..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-get.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - -

-

-

-
-

-
-
-
- - -
-
-
-

- - -

- - diff --git a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-list.html b/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-list.html deleted file mode 100644 index 0671f24ba3..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/WEB-INF/views/task-list.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - -

-
    -
  • -

    -

    - -
  • -
-

- - -

- - diff --git a/spring-dispatcher-servlet/src/main/webapp/public/css/base.css b/spring-dispatcher-servlet/src/main/webapp/public/css/base.css deleted file mode 100644 index 4d3c2597cf..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/public/css/base.css +++ /dev/null @@ -1,8 +0,0 @@ -a.button { - -webkit-appearance: button; - -moz-appearance: button; - appearance: button; - text-decoration: none; - color: #2196f3; - background-color: #e0e0e0; -} diff --git a/spring-dispatcher-servlet/src/main/webapp/public/css/themes/post_it.css b/spring-dispatcher-servlet/src/main/webapp/public/css/themes/post_it.css deleted file mode 100644 index 578781ec83..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/public/css/themes/post_it.css +++ /dev/null @@ -1,8 +0,0 @@ -@import url('https://fonts.googleapis.com/css?family=Indie+Flower'); - -* { - font-family: 'Indie Flower', sans-serif; - font-size: 18px; - color: #ffeb3b; - background-color: #212121; -} diff --git a/spring-dispatcher-servlet/src/main/webapp/public/css/themes/robotask.css b/spring-dispatcher-servlet/src/main/webapp/public/css/themes/robotask.css deleted file mode 100644 index 8c0121b536..0000000000 --- a/spring-dispatcher-servlet/src/main/webapp/public/css/themes/robotask.css +++ /dev/null @@ -1,8 +0,0 @@ -@import url('https://fonts.googleapis.com/css?family=Roboto'); - -* { - font-family: Roboto, sans-serif; - font-size: 1em; - color: #212121; - background-color: #fafafa; -} diff --git a/spring-dispatcher-servlet/src/main/webapp/resources/css/default.css b/spring-dispatcher-servlet/src/main/webapp/resources/css/default.css new file mode 100644 index 0000000000..7f20f36d96 --- /dev/null +++ b/spring-dispatcher-servlet/src/main/webapp/resources/css/default.css @@ -0,0 +1,4 @@ +h2 { + color: green; + font-weight: 400; +} \ No newline at end of file diff --git a/spring-dispatcher-servlet/src/main/webapp/resources/css/example.css b/spring-dispatcher-servlet/src/main/webapp/resources/css/example.css new file mode 100644 index 0000000000..fe31b0396a --- /dev/null +++ b/spring-dispatcher-servlet/src/main/webapp/resources/css/example.css @@ -0,0 +1,4 @@ +h2 { + color: red; + font-weight: 700; +} \ No newline at end of file diff --git a/spring-exceptions/pom.xml b/spring-exceptions/pom.xml index a8254151aa..8733f8f2f4 100644 --- a/spring-exceptions/pom.xml +++ b/spring-exceptions/pom.xml @@ -15,11 +15,23 @@ org.springframework spring-web ${org.springframework.version} + + + commons-logging + commons-logging + +
org.springframework spring-webmvc ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-freemarker/src/main/resources/log4j.xml b/spring-freemarker/src/main/resources/log4j.xml deleted file mode 100644 index ae7d4b5ca4..0000000000 --- a/spring-freemarker/src/main/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-freemarker/src/test/resources/log4j.xml b/spring-freemarker/src/test/resources/log4j.xml deleted file mode 100644 index 9b1538d31a..0000000000 --- a/spring-freemarker/src/test/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-hibernate3/pom.xml b/spring-hibernate3/pom.xml index f7b198a2b1..c45c9bb15e 100644 --- a/spring-hibernate3/pom.xml +++ b/spring-hibernate3/pom.xml @@ -14,6 +14,12 @@ org.springframework spring-context ${org.springframework.version} + + + commons-logging + commons-logging + + diff --git a/spring-hibernate4/pom.xml b/spring-hibernate4/pom.xml index dbacb3a60a..8ba0a3700c 100644 --- a/spring-hibernate4/pom.xml +++ b/spring-hibernate4/pom.xml @@ -14,6 +14,12 @@ org.springframework spring-context ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-hibernate5/pom.xml b/spring-hibernate5/pom.xml index 752cbdba1d..ed127c34c1 100644 --- a/spring-hibernate5/pom.xml +++ b/spring-hibernate5/pom.xml @@ -14,6 +14,12 @@ org.springframework spring-context ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-integration/pom.xml b/spring-integration/pom.xml index 0aa8fed598..34c40cb00f 100644 --- a/spring-integration/pom.xml +++ b/spring-integration/pom.xml @@ -16,7 +16,6 @@ 1.1.4.RELEASE 1.4.7 1.1.1 - 1.2.17 4.12 2.10 @@ -97,6 +96,12 @@ org.springframework.integration spring-integration-core ${spring.integration.version} + + + commons-logging + commons-logging + + javax.activation @@ -109,11 +114,6 @@ mail ${javax-mail.version} - - log4j - log4j - ${log4j.version} - org.springframework.integration spring-integration-twitter diff --git a/spring-integration/src/main/resources/log4j.xml b/spring-integration/src/main/resources/log4j.xml deleted file mode 100644 index cfa93a8037..0000000000 --- a/spring-integration/src/main/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml index e6c8ea6ef5..8d39da9733 100644 --- a/spring-jersey/pom.xml +++ b/spring-jersey/pom.xml @@ -134,6 +134,12 @@ httpclient ${httpclient.version} test + + + commons-logging + commons-logging + + diff --git a/spring-jms/pom.xml b/spring-jms/pom.xml index de7c734316..da71725d8f 100644 --- a/spring-jms/pom.xml +++ b/spring-jms/pom.xml @@ -23,6 +23,12 @@ org.springframework spring-jms ${springframework.version} + + + commons-logging + commons-logging + + diff --git a/spring-jooq/pom.xml b/spring-jooq/pom.xml index e067e9b47f..4dce21116f 100644 --- a/spring-jooq/pom.xml +++ b/spring-jooq/pom.xml @@ -35,6 +35,12 @@ org.springframework spring-context + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-jpa/pom.xml b/spring-jpa/pom.xml index 3ca373acea..9ecbddb34d 100644 --- a/spring-jpa/pom.xml +++ b/spring-jpa/pom.xml @@ -16,6 +16,12 @@ org.springframework spring-orm ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-kafka/README.md b/spring-kafka/README.md index c8f01cc28b..291bbca6f6 100644 --- a/spring-kafka/README.md +++ b/spring-kafka/README.md @@ -1,4 +1,10 @@ -# Spring Kakfa +### Relevant articles + +- [Intro to Apache Kafka with Spring](http://www.baeldung.com/spring-kafka) + + + +# Spring Kafka This is a simple Spring Boot app to demonstrate sending and receiving of messages in Kafka using spring-kafka. @@ -12,18 +18,18 @@ As Kafka topics are not created automatically by default, this application requi When the application runs successfully, following output is logged on to console (along with spring logs): #### Message received from the 'baeldung' topic by the basic listeners with groups foo and bar ->Received Messasge in group 'foo': Hello, World!
-Received Messasge in group 'bar': Hello, World! +>Received Message in group 'foo': Hello, World!
+Received Message in group 'bar': Hello, World! #### Message received from the 'baeldung' topic, with the partition info ->Received Messasge: Hello, World! from partition: 0 +>Received Message: Hello, World! from partition: 0 #### Message received from the 'partitioned' topic, only from specific partitions >Received Message: Hello To Partioned Topic! from partition: 0
Received Message: Hello To Partioned Topic! from partition: 3 #### Message received from the 'filtered' topic after filtering ->Recieved Message in filtered listener: Hello Baeldung! +>Received Message in filtered listener: Hello Baeldung! #### Message (Serialized Java Object) received from the 'greeting' topic ->Recieved greeting message: Greetings, World!! \ No newline at end of file +>Received greeting message: Greetings, World!! diff --git a/spring-ldap/pom.xml b/spring-ldap/pom.xml index 55014897c4..123e72672a 100644 --- a/spring-ldap/pom.xml +++ b/spring-ldap/pom.xml @@ -107,6 +107,12 @@ spring-ldap-test ${spring-ldap.version} test + + + commons-logging + commons-logging + +
diff --git a/spring-mvc-forms/pom.xml b/spring-mvc-forms/pom.xml index e5ffb52801..12b0ba7e7c 100644 --- a/spring-mvc-forms/pom.xml +++ b/spring-mvc-forms/pom.xml @@ -15,6 +15,12 @@ org.springframework spring-webmvc ${springframework.version} + + + commons-logging + commons-logging + +
diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 4d3e58558b..533d37fe00 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -21,3 +21,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring @RequestMapping New Shortcut Annotations](http://www.baeldung.com/spring-new-requestmapping-shortcuts) - [Guide to Spring Handler Mappings](http://www.baeldung.com/spring-handler-mappings) - [Uploading and Displaying Excel Files with Spring MVC](http://www.baeldung.com/spring-mvc-excel-files) +- [Spring MVC Custom Validation](http://www.baeldung.com/spring-mvc-custom-validator) diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index dcf740b22b..f47b723beb 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -84,6 +84,12 @@ net.sourceforge.htmlunit htmlunit ${net.sourceforge.htmlunit} + + + commons-logging + commons-logging + + @@ -116,11 +122,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index a004eae4d9..6e96775f26 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -27,11 +27,6 @@ javax.servlet-api 3.1.0 - - commons-logging - commons-logging - 1.2 - org.springframework spring-webmvc @@ -46,6 +41,12 @@ org.springframework spring-core ${springframework.version} + + + commons-logging + commons-logging + + javax.servlet.jsp diff --git a/spring-mvc-tiles/pom.xml b/spring-mvc-tiles/pom.xml index 400f79fbe1..684c3abec7 100644 --- a/spring-mvc-tiles/pom.xml +++ b/spring-mvc-tiles/pom.xml @@ -25,6 +25,12 @@ org.springframework spring-core ${springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-mvc-velocity/pom.xml b/spring-mvc-velocity/pom.xml index 0a9b3a016e..51348acd4a 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-mvc-velocity/pom.xml @@ -26,6 +26,12 @@ org.springframework spring-core ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework @@ -52,6 +58,12 @@ org.apache.velocity velocity-tools ${velocity-tools.version} + + + commons-logging + commons-logging + + diff --git a/spring-mvc-web-vs-initializer/pom.xml b/spring-mvc-web-vs-initializer/pom.xml index 8fe8893903..1d02039ead 100644 --- a/spring-mvc-web-vs-initializer/pom.xml +++ b/spring-mvc-web-vs-initializer/pom.xml @@ -24,6 +24,12 @@ org.springframework spring-web + + + commons-logging + commons-logging + + org.springframework @@ -72,10 +78,6 @@ jcl-over-slf4j - - org.slf4j - log4j-over-slf4j - diff --git a/spring-mvc-xml/pom.xml b/spring-mvc-xml/pom.xml index 86eb17da64..142b400e5f 100644 --- a/spring-mvc-xml/pom.xml +++ b/spring-mvc-xml/pom.xml @@ -16,6 +16,12 @@ org.springframework spring-web ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework @@ -64,11 +70,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - @@ -121,7 +122,11 @@ com.fasterxml.jackson.core jackson-databind - + + commons-logging + commons-logging + + diff --git a/spring-remoting/pom.xml b/spring-remoting/pom.xml index 52d670a726..96e808477f 100644 --- a/spring-remoting/pom.xml +++ b/spring-remoting/pom.xml @@ -36,6 +36,7 @@ remoting-http remoting-hessian-burlap + remoting-amqp \ No newline at end of file diff --git a/spring-remoting/remoting-amqp/pom.xml b/spring-remoting/remoting-amqp/pom.xml new file mode 100644 index 0000000000..6a7d0804dc --- /dev/null +++ b/spring-remoting/remoting-amqp/pom.xml @@ -0,0 +1,21 @@ + + + spring-remoting + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + remoting-amqp + pom + + + + remoting-amqp + + remoting-amqp-server + remoting-amqp-client + + + diff --git a/spring-remoting/remoting-amqp/remoting-amqp-client/pom.xml b/spring-remoting/remoting-amqp/remoting-amqp-client/pom.xml new file mode 100644 index 0000000000..9a2d0bf9cc --- /dev/null +++ b/spring-remoting/remoting-amqp/remoting-amqp-client/pom.xml @@ -0,0 +1,36 @@ + + + remoting-amqp + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + remoting-amqp-client + jar + + remoting-amqp-client + http://maven.apache.org + + + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + com.baeldung + api + + + diff --git a/spring-remoting/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java b/spring-remoting/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java new file mode 100644 index 0000000000..def80f6b5e --- /dev/null +++ b/spring-remoting/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java @@ -0,0 +1,46 @@ +package com.baeldung.client; + +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import org.springframework.amqp.core.*; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.remoting.client.AmqpProxyFactoryBean; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import static java.lang.System.out; + +@SpringBootApplication public class AmqpClient { + + @Bean Queue queue() { + return new Queue("remotingQueue"); + } + + @Bean AmqpProxyFactoryBean amqpFactoryBean(AmqpTemplate amqpTemplate) { + AmqpProxyFactoryBean factoryBean = new AmqpProxyFactoryBean(); + factoryBean.setServiceInterface(CabBookingService.class); + factoryBean.setAmqpTemplate(amqpTemplate); + return factoryBean; + } + + @Bean Exchange directExchange(Queue someQueue) { + DirectExchange exchange = new DirectExchange("remoting.exchange"); + BindingBuilder.bind(someQueue).to(exchange).with("remoting.binding"); + return exchange; + } + + @Bean RabbitTemplate amqpTemplate(ConnectionFactory factory) { + RabbitTemplate template = new RabbitTemplate(factory); + template.setRoutingKey("remoting.binding"); + template.setExchange("remoting.exchange"); + return template; + } + + public static void main(String[] args) throws BookingException { + CabBookingService service = SpringApplication.run(AmqpClient.class, args).getBean(CabBookingService.class); + out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037")); + } + +} diff --git a/spring-remoting/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties b/spring-remoting/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties new file mode 100644 index 0000000000..8df44a7c8d --- /dev/null +++ b/spring-remoting/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties @@ -0,0 +1,19 @@ +# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'. +# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details. +spring.rabbitmq.dynamic=true + +# The port to which the client should connect defaults to 5672. +spring.rabbitmq.port=32769 + +# Username and password +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest + +# The host, defaults to localhost. +spring.rabbitmq.host=192.168.99.100 + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.springframework.amqp=TRACE + diff --git a/spring-remoting/remoting-amqp/remoting-amqp-server/pom.xml b/spring-remoting/remoting-amqp/remoting-amqp-server/pom.xml new file mode 100644 index 0000000000..4d3f4da765 --- /dev/null +++ b/spring-remoting/remoting-amqp/remoting-amqp-server/pom.xml @@ -0,0 +1,46 @@ + + + remoting-amqp + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + remoting-amqp-server + jar + + remoting-amqp-server + http://maven.apache.org + + + UTF-8 + + + + + com.baeldung + api + ${project.version} + + + org.springframework.boot + spring-boot-starter-amqp + + + com.baeldung + api + 1.0-SNAPSHOT + + + junit + junit + test + + + com.baeldung + spring-remoting-http-server + 1.0-SNAPSHOT + + + diff --git a/spring-remoting/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java b/spring-remoting/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java new file mode 100644 index 0000000000..f0155b2141 --- /dev/null +++ b/spring-remoting/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java @@ -0,0 +1,53 @@ +package com.baeldung.server; + +import com.baeldung.api.CabBookingService; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.amqp.remoting.service.AmqpInvokerServiceExporter; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration @ComponentScan @EnableAutoConfiguration +public class AmqpServer { + + /* + Please note that + - CachingConnectionFactory + - RabbitAdmin + - AmqpTemplate + are automatically declared by SpringBoot. + */ + + @Bean CabBookingService bookingService() { + return new CabBookingServiceImpl(); + } + + @Bean Queue queue() { + return new Queue("remotingQueue"); + } + + @Bean AmqpInvokerServiceExporter exporter(CabBookingService implementation, AmqpTemplate template) { + AmqpInvokerServiceExporter exporter = new AmqpInvokerServiceExporter(); + exporter.setServiceInterface(CabBookingService.class); + exporter.setService(implementation); + exporter.setAmqpTemplate(template); + return exporter; + } + + @Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, AmqpInvokerServiceExporter exporter, Queue queue) { + SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(factory); + container.setMessageListener(exporter); + container.setQueueNames(queue.getName()); + return container; + } + + public static void main(String[] args) { + SpringApplication.run(AmqpServer.class, args); + } + +} \ No newline at end of file diff --git a/spring-remoting/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties b/spring-remoting/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties new file mode 100644 index 0000000000..8df44a7c8d --- /dev/null +++ b/spring-remoting/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties @@ -0,0 +1,19 @@ +# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'. +# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details. +spring.rabbitmq.dynamic=true + +# The port to which the client should connect defaults to 5672. +spring.rabbitmq.port=32769 + +# Username and password +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest + +# The host, defaults to localhost. +spring.rabbitmq.host=192.168.99.100 + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.springframework.amqp=TRACE + diff --git a/spring-rest/README.md b/spring-rest/README.md index 85f0e13732..66c893e45f 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -13,3 +13,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to UriComponentsBuilder in Spring](http://www.baeldung.com/spring-uricomponentsbuilder) - [Introduction to FindBugs](http://www.baeldung.com/intro-to-findbugs) - [A Custom Media Type for a Spring REST API](http://www.baeldung.com/spring-rest-custom-media-type) +- [HTTP PUT vs HTTP PATCH in a REST API](http://www.baeldung.com/http-put-patch-difference-spring) +- [Exploring the Spring Boot TestRestTemplate](http://www.baeldung.com/spring-boot-testresttemplate) diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 6afe4004c3..9b1b9a2847 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -122,10 +122,6 @@ jcl-over-slf4j - - org.slf4j - log4j-over-slf4j - diff --git a/spring-rest/src/main/java/com/baeldung/produceimage/README.md b/spring-rest/src/main/java/com/baeldung/produceimage/README.md new file mode 100644 index 0000000000..acd546598d --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/produceimage/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Returning an Image or a File with Spring](http://www.baeldung.com/spring-controller-return-image-file) diff --git a/roo/pom.xml b/spring-roo/pom.xml similarity index 100% rename from roo/pom.xml rename to spring-roo/pom.xml diff --git a/roo/src/main/java/com/baeldung/RooApplication.java b/spring-roo/src/main/java/com/baeldung/RooApplication.java similarity index 100% rename from roo/src/main/java/com/baeldung/RooApplication.java rename to spring-roo/src/main/java/com/baeldung/RooApplication.java diff --git a/roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration.java b/spring-roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration.java similarity index 100% rename from roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration.java rename to spring-roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration.java diff --git a/roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration.aj b/spring-roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration.aj similarity index 100% rename from roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration.aj rename to spring-roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration.aj diff --git a/roo/src/main/java/com/baeldung/config/WebMvcConfiguration.java b/spring-roo/src/main/java/com/baeldung/config/WebMvcConfiguration.java similarity index 100% rename from roo/src/main/java/com/baeldung/config/WebMvcConfiguration.java rename to spring-roo/src/main/java/com/baeldung/config/WebMvcConfiguration.java diff --git a/roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_ThymeleafUIConfiguration.aj b/spring-roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_ThymeleafUIConfiguration.aj similarity index 100% rename from roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_ThymeleafUIConfiguration.aj rename to spring-roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_ThymeleafUIConfiguration.aj diff --git a/roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_WebMvcConfiguration.aj b/spring-roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_WebMvcConfiguration.aj similarity index 100% rename from roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_WebMvcConfiguration.aj rename to spring-roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_WebMvcConfiguration.aj diff --git a/roo/src/main/java/com/baeldung/config/jackson/DomainModelModule.java b/spring-roo/src/main/java/com/baeldung/config/jackson/DomainModelModule.java similarity index 100% rename from roo/src/main/java/com/baeldung/config/jackson/DomainModelModule.java rename to spring-roo/src/main/java/com/baeldung/config/jackson/DomainModelModule.java diff --git a/roo/src/main/java/com/baeldung/config/jackson/DomainModelModule_Roo_DomainModelModule.aj b/spring-roo/src/main/java/com/baeldung/config/jackson/DomainModelModule_Roo_DomainModelModule.aj similarity index 100% rename from roo/src/main/java/com/baeldung/config/jackson/DomainModelModule_Roo_DomainModelModule.aj rename to spring-roo/src/main/java/com/baeldung/config/jackson/DomainModelModule_Roo_DomainModelModule.aj diff --git a/roo/src/main/java/com/baeldung/domain/Book.java b/spring-roo/src/main/java/com/baeldung/domain/Book.java similarity index 100% rename from roo/src/main/java/com/baeldung/domain/Book.java rename to spring-roo/src/main/java/com/baeldung/domain/Book.java diff --git a/roo/src/main/java/com/baeldung/domain/Book_Roo_Equals.aj b/spring-roo/src/main/java/com/baeldung/domain/Book_Roo_Equals.aj similarity index 100% rename from roo/src/main/java/com/baeldung/domain/Book_Roo_Equals.aj rename to spring-roo/src/main/java/com/baeldung/domain/Book_Roo_Equals.aj diff --git a/roo/src/main/java/com/baeldung/domain/Book_Roo_JavaBean.aj b/spring-roo/src/main/java/com/baeldung/domain/Book_Roo_JavaBean.aj similarity index 100% rename from roo/src/main/java/com/baeldung/domain/Book_Roo_JavaBean.aj rename to spring-roo/src/main/java/com/baeldung/domain/Book_Roo_JavaBean.aj diff --git a/roo/src/main/java/com/baeldung/domain/Book_Roo_Jpa_Entity.aj b/spring-roo/src/main/java/com/baeldung/domain/Book_Roo_Jpa_Entity.aj similarity index 100% rename from roo/src/main/java/com/baeldung/domain/Book_Roo_Jpa_Entity.aj rename to spring-roo/src/main/java/com/baeldung/domain/Book_Roo_Jpa_Entity.aj diff --git a/roo/src/main/java/com/baeldung/domain/Book_Roo_ToString.aj b/spring-roo/src/main/java/com/baeldung/domain/Book_Roo_ToString.aj similarity index 100% rename from roo/src/main/java/com/baeldung/domain/Book_Roo_ToString.aj rename to spring-roo/src/main/java/com/baeldung/domain/Book_Roo_ToString.aj diff --git a/roo/src/main/java/com/baeldung/repository/BookRepository.java b/spring-roo/src/main/java/com/baeldung/repository/BookRepository.java similarity index 100% rename from roo/src/main/java/com/baeldung/repository/BookRepository.java rename to spring-roo/src/main/java/com/baeldung/repository/BookRepository.java diff --git a/roo/src/main/java/com/baeldung/repository/BookRepositoryCustom.java b/spring-roo/src/main/java/com/baeldung/repository/BookRepositoryCustom.java similarity index 100% rename from roo/src/main/java/com/baeldung/repository/BookRepositoryCustom.java rename to spring-roo/src/main/java/com/baeldung/repository/BookRepositoryCustom.java diff --git a/roo/src/main/java/com/baeldung/repository/BookRepositoryCustom_Roo_Jpa_Repository_Custom.aj b/spring-roo/src/main/java/com/baeldung/repository/BookRepositoryCustom_Roo_Jpa_Repository_Custom.aj similarity index 100% rename from roo/src/main/java/com/baeldung/repository/BookRepositoryCustom_Roo_Jpa_Repository_Custom.aj rename to spring-roo/src/main/java/com/baeldung/repository/BookRepositoryCustom_Roo_Jpa_Repository_Custom.aj diff --git a/roo/src/main/java/com/baeldung/repository/BookRepositoryImpl.java b/spring-roo/src/main/java/com/baeldung/repository/BookRepositoryImpl.java similarity index 100% rename from roo/src/main/java/com/baeldung/repository/BookRepositoryImpl.java rename to spring-roo/src/main/java/com/baeldung/repository/BookRepositoryImpl.java diff --git a/roo/src/main/java/com/baeldung/repository/BookRepositoryImpl_Roo_Jpa_Repository_Impl.aj b/spring-roo/src/main/java/com/baeldung/repository/BookRepositoryImpl_Roo_Jpa_Repository_Impl.aj similarity index 100% rename from roo/src/main/java/com/baeldung/repository/BookRepositoryImpl_Roo_Jpa_Repository_Impl.aj rename to spring-roo/src/main/java/com/baeldung/repository/BookRepositoryImpl_Roo_Jpa_Repository_Impl.aj diff --git a/roo/src/main/java/com/baeldung/repository/BookRepository_Roo_Jpa_Repository.aj b/spring-roo/src/main/java/com/baeldung/repository/BookRepository_Roo_Jpa_Repository.aj similarity index 100% rename from roo/src/main/java/com/baeldung/repository/BookRepository_Roo_Jpa_Repository.aj rename to spring-roo/src/main/java/com/baeldung/repository/BookRepository_Roo_Jpa_Repository.aj diff --git a/roo/src/main/java/com/baeldung/service/api/BookService.java b/spring-roo/src/main/java/com/baeldung/service/api/BookService.java similarity index 100% rename from roo/src/main/java/com/baeldung/service/api/BookService.java rename to spring-roo/src/main/java/com/baeldung/service/api/BookService.java diff --git a/roo/src/main/java/com/baeldung/service/api/BookService_Roo_Service.aj b/spring-roo/src/main/java/com/baeldung/service/api/BookService_Roo_Service.aj similarity index 100% rename from roo/src/main/java/com/baeldung/service/api/BookService_Roo_Service.aj rename to spring-roo/src/main/java/com/baeldung/service/api/BookService_Roo_Service.aj diff --git a/roo/src/main/java/com/baeldung/service/impl/BookServiceImpl.java b/spring-roo/src/main/java/com/baeldung/service/impl/BookServiceImpl.java similarity index 100% rename from roo/src/main/java/com/baeldung/service/impl/BookServiceImpl.java rename to spring-roo/src/main/java/com/baeldung/service/impl/BookServiceImpl.java diff --git a/roo/src/main/java/com/baeldung/service/impl/BookServiceImpl_Roo_Service_Impl.aj b/spring-roo/src/main/java/com/baeldung/service/impl/BookServiceImpl_Roo_Service_Impl.aj similarity index 100% rename from roo/src/main/java/com/baeldung/service/impl/BookServiceImpl_Roo_Service_Impl.aj rename to spring-roo/src/main/java/com/baeldung/service/impl/BookServiceImpl_Roo_Service_Impl.aj diff --git a/roo/src/main/java/com/baeldung/web/BookDeserializer.java b/spring-roo/src/main/java/com/baeldung/web/BookDeserializer.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/BookDeserializer.java rename to spring-roo/src/main/java/com/baeldung/web/BookDeserializer.java diff --git a/roo/src/main/java/com/baeldung/web/BookDeserializer_Roo_EntityDeserializer.aj b/spring-roo/src/main/java/com/baeldung/web/BookDeserializer_Roo_EntityDeserializer.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BookDeserializer_Roo_EntityDeserializer.aj rename to spring-roo/src/main/java/com/baeldung/web/BookDeserializer_Roo_EntityDeserializer.aj diff --git a/roo/src/main/java/com/baeldung/web/BookJsonMixin.java b/spring-roo/src/main/java/com/baeldung/web/BookJsonMixin.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/BookJsonMixin.java rename to spring-roo/src/main/java/com/baeldung/web/BookJsonMixin.java diff --git a/roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController.java b/spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController.java rename to spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController.java diff --git a/roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Controller.aj b/spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Controller.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Controller.aj rename to spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Controller.aj diff --git a/roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Thymeleaf.aj b/spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Thymeleaf.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Thymeleaf.aj rename to spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafController_Roo_Thymeleaf.aj diff --git a/roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory.java b/spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory.java rename to spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory.java diff --git a/roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory_Roo_LinkFactory.aj b/spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory_Roo_LinkFactory.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory_Roo_LinkFactory.aj rename to spring-roo/src/main/java/com/baeldung/web/BooksCollectionThymeleafLinkFactory_Roo_LinkFactory.aj diff --git a/roo/src/main/java/com/baeldung/web/BooksItemThymeleafController.java b/spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafController.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksItemThymeleafController.java rename to spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafController.java diff --git a/roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Controller.aj b/spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Controller.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Controller.aj rename to spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Controller.aj diff --git a/roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Thymeleaf.aj b/spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Thymeleaf.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Thymeleaf.aj rename to spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafController_Roo_Thymeleaf.aj diff --git a/roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory.java b/spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory.java rename to spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory.java diff --git a/roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory_Roo_LinkFactory.aj b/spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory_Roo_LinkFactory.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory_Roo_LinkFactory.aj rename to spring-roo/src/main/java/com/baeldung/web/BooksItemThymeleafLinkFactory_Roo_LinkFactory.aj diff --git a/roo/src/main/java/com/baeldung/web/MainController.java b/spring-roo/src/main/java/com/baeldung/web/MainController.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/MainController.java rename to spring-roo/src/main/java/com/baeldung/web/MainController.java diff --git a/roo/src/main/java/com/baeldung/web/MainController_Roo_Thymeleaf_MainController.aj b/spring-roo/src/main/java/com/baeldung/web/MainController_Roo_Thymeleaf_MainController.aj similarity index 100% rename from roo/src/main/java/com/baeldung/web/MainController_Roo_Thymeleaf_MainController.aj rename to spring-roo/src/main/java/com/baeldung/web/MainController_Roo_Thymeleaf_MainController.aj diff --git a/roo/src/main/java/com/baeldung/web/reports/ExportingErrorException.java b/spring-roo/src/main/java/com/baeldung/web/reports/ExportingErrorException.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/reports/ExportingErrorException.java rename to spring-roo/src/main/java/com/baeldung/web/reports/ExportingErrorException.java diff --git a/roo/src/main/java/com/baeldung/web/reports/JasperReportsCsvExporter.java b/spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsCsvExporter.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/reports/JasperReportsCsvExporter.java rename to spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsCsvExporter.java diff --git a/roo/src/main/java/com/baeldung/web/reports/JasperReportsExporter.java b/spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsExporter.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/reports/JasperReportsExporter.java rename to spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsExporter.java diff --git a/roo/src/main/java/com/baeldung/web/reports/JasperReportsPdfExporter.java b/spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsPdfExporter.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/reports/JasperReportsPdfExporter.java rename to spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsPdfExporter.java diff --git a/roo/src/main/java/com/baeldung/web/reports/JasperReportsXlsExporter.java b/spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsXlsExporter.java similarity index 100% rename from roo/src/main/java/com/baeldung/web/reports/JasperReportsXlsExporter.java rename to spring-roo/src/main/java/com/baeldung/web/reports/JasperReportsXlsExporter.java diff --git a/roo/src/main/resources/application-dev.properties b/spring-roo/src/main/resources/application-dev.properties similarity index 100% rename from roo/src/main/resources/application-dev.properties rename to spring-roo/src/main/resources/application-dev.properties diff --git a/roo/src/main/resources/application.properties b/spring-roo/src/main/resources/application.properties similarity index 100% rename from roo/src/main/resources/application.properties rename to spring-roo/src/main/resources/application.properties diff --git a/roo/src/main/resources/banner.txt b/spring-roo/src/main/resources/banner.txt similarity index 100% rename from roo/src/main/resources/banner.txt rename to spring-roo/src/main/resources/banner.txt diff --git a/roo/src/main/resources/messages.properties b/spring-roo/src/main/resources/messages.properties similarity index 100% rename from roo/src/main/resources/messages.properties rename to spring-roo/src/main/resources/messages.properties diff --git a/roo/src/main/resources/static/public/css/springroo.css b/spring-roo/src/main/resources/static/public/css/springroo.css similarity index 100% rename from roo/src/main/resources/static/public/css/springroo.css rename to spring-roo/src/main/resources/static/public/css/springroo.css diff --git a/roo/src/main/resources/static/public/css/theme.css b/spring-roo/src/main/resources/static/public/css/theme.css similarity index 100% rename from roo/src/main/resources/static/public/css/theme.css rename to spring-roo/src/main/resources/static/public/css/theme.css diff --git a/roo/src/main/resources/static/public/fonts/fontawesome-webfont.eot b/spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.eot similarity index 100% rename from roo/src/main/resources/static/public/fonts/fontawesome-webfont.eot rename to spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.eot diff --git a/roo/src/main/resources/static/public/fonts/fontawesome-webfont.svg b/spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.svg similarity index 100% rename from roo/src/main/resources/static/public/fonts/fontawesome-webfont.svg rename to spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.svg diff --git a/roo/src/main/resources/static/public/fonts/fontawesome-webfont.ttf b/spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.ttf similarity index 100% rename from roo/src/main/resources/static/public/fonts/fontawesome-webfont.ttf rename to spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.ttf diff --git a/roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff b/spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff similarity index 100% rename from roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff rename to spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff diff --git a/roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff2 b/spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff2 similarity index 100% rename from roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff2 rename to spring-roo/src/main/resources/static/public/fonts/fontawesome-webfont.woff2 diff --git a/roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.eot b/spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.eot rename to spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.eot diff --git a/roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.svg b/spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.svg rename to spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.svg diff --git a/roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.ttf b/spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.ttf rename to spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.ttf diff --git a/roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff b/spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff rename to spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff diff --git a/roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff2 b/spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff2 rename to spring-roo/src/main/resources/static/public/fonts/glyphicons-halflings-regular.woff2 diff --git a/roo/src/main/resources/static/public/img/apple-touch-icon.png b/spring-roo/src/main/resources/static/public/img/apple-touch-icon.png similarity index 100% rename from roo/src/main/resources/static/public/img/apple-touch-icon.png rename to spring-roo/src/main/resources/static/public/img/apple-touch-icon.png diff --git a/roo/src/main/resources/static/public/img/en.png b/spring-roo/src/main/resources/static/public/img/en.png similarity index 100% rename from roo/src/main/resources/static/public/img/en.png rename to spring-roo/src/main/resources/static/public/img/en.png diff --git a/roo/src/main/resources/static/public/img/es.png b/spring-roo/src/main/resources/static/public/img/es.png similarity index 100% rename from roo/src/main/resources/static/public/img/es.png rename to spring-roo/src/main/resources/static/public/img/es.png diff --git a/roo/src/main/resources/static/public/img/favicon.ico b/spring-roo/src/main/resources/static/public/img/favicon.ico similarity index 100% rename from roo/src/main/resources/static/public/img/favicon.ico rename to spring-roo/src/main/resources/static/public/img/favicon.ico diff --git a/roo/src/main/resources/static/public/img/geo.png b/spring-roo/src/main/resources/static/public/img/geo.png similarity index 100% rename from roo/src/main/resources/static/public/img/geo.png rename to spring-roo/src/main/resources/static/public/img/geo.png diff --git a/roo/src/main/resources/static/public/img/logo.png b/spring-roo/src/main/resources/static/public/img/logo.png similarity index 100% rename from roo/src/main/resources/static/public/img/logo.png rename to spring-roo/src/main/resources/static/public/img/logo.png diff --git a/roo/src/main/resources/static/public/img/owasp_logo.png b/spring-roo/src/main/resources/static/public/img/owasp_logo.png similarity index 100% rename from roo/src/main/resources/static/public/img/owasp_logo.png rename to spring-roo/src/main/resources/static/public/img/owasp_logo.png diff --git a/roo/src/main/resources/static/public/img/springroo-logo.png b/spring-roo/src/main/resources/static/public/img/springroo-logo.png similarity index 100% rename from roo/src/main/resources/static/public/img/springroo-logo.png rename to spring-roo/src/main/resources/static/public/img/springroo-logo.png diff --git a/roo/src/main/resources/static/public/js/dataTables.advanced.js b/spring-roo/src/main/resources/static/public/js/dataTables.advanced.js similarity index 100% rename from roo/src/main/resources/static/public/js/dataTables.advanced.js rename to spring-roo/src/main/resources/static/public/js/dataTables.advanced.js diff --git a/roo/src/main/resources/static/public/js/datatables-defaults.js b/spring-roo/src/main/resources/static/public/js/datatables-defaults.js similarity index 100% rename from roo/src/main/resources/static/public/js/datatables-defaults.js rename to spring-roo/src/main/resources/static/public/js/datatables-defaults.js diff --git a/roo/src/main/resources/static/public/js/datetimepicker-defaults.js b/spring-roo/src/main/resources/static/public/js/datetimepicker-defaults.js similarity index 100% rename from roo/src/main/resources/static/public/js/datetimepicker-defaults.js rename to spring-roo/src/main/resources/static/public/js/datetimepicker-defaults.js diff --git a/roo/src/main/resources/static/public/js/inputmask-defaults.js b/spring-roo/src/main/resources/static/public/js/inputmask-defaults.js similarity index 100% rename from roo/src/main/resources/static/public/js/inputmask-defaults.js rename to spring-roo/src/main/resources/static/public/js/inputmask-defaults.js diff --git a/roo/src/main/resources/static/public/js/main.js b/spring-roo/src/main/resources/static/public/js/main.js similarity index 100% rename from roo/src/main/resources/static/public/js/main.js rename to spring-roo/src/main/resources/static/public/js/main.js diff --git a/roo/src/main/resources/static/public/js/moment-defaults.js b/spring-roo/src/main/resources/static/public/js/moment-defaults.js similarity index 100% rename from roo/src/main/resources/static/public/js/moment-defaults.js rename to spring-roo/src/main/resources/static/public/js/moment-defaults.js diff --git a/roo/src/main/resources/static/public/js/moment-locale-es.js b/spring-roo/src/main/resources/static/public/js/moment-locale-es.js similarity index 100% rename from roo/src/main/resources/static/public/js/moment-locale-es.js rename to spring-roo/src/main/resources/static/public/js/moment-locale-es.js diff --git a/roo/src/main/resources/static/public/js/select2-defaults.js b/spring-roo/src/main/resources/static/public/js/select2-defaults.js similarity index 100% rename from roo/src/main/resources/static/public/js/select2-defaults.js rename to spring-roo/src/main/resources/static/public/js/select2-defaults.js diff --git a/roo/src/main/resources/static/public/js/validation-defaults.js b/spring-roo/src/main/resources/static/public/js/validation-defaults.js similarity index 100% rename from roo/src/main/resources/static/public/js/validation-defaults.js rename to spring-roo/src/main/resources/static/public/js/validation-defaults.js diff --git a/roo/src/main/resources/templates/accessibility.html b/spring-roo/src/main/resources/templates/accessibility.html similarity index 100% rename from roo/src/main/resources/templates/accessibility.html rename to spring-roo/src/main/resources/templates/accessibility.html diff --git a/roo/src/main/resources/templates/books/create.html b/spring-roo/src/main/resources/templates/books/create.html similarity index 100% rename from roo/src/main/resources/templates/books/create.html rename to spring-roo/src/main/resources/templates/books/create.html diff --git a/roo/src/main/resources/templates/books/edit.html b/spring-roo/src/main/resources/templates/books/edit.html similarity index 100% rename from roo/src/main/resources/templates/books/edit.html rename to spring-roo/src/main/resources/templates/books/edit.html diff --git a/roo/src/main/resources/templates/books/list.html b/spring-roo/src/main/resources/templates/books/list.html similarity index 100% rename from roo/src/main/resources/templates/books/list.html rename to spring-roo/src/main/resources/templates/books/list.html diff --git a/roo/src/main/resources/templates/books/show.html b/spring-roo/src/main/resources/templates/books/show.html similarity index 100% rename from roo/src/main/resources/templates/books/show.html rename to spring-roo/src/main/resources/templates/books/show.html diff --git a/roo/src/main/resources/templates/books/showInline.html b/spring-roo/src/main/resources/templates/books/showInline.html similarity index 100% rename from roo/src/main/resources/templates/books/showInline.html rename to spring-roo/src/main/resources/templates/books/showInline.html diff --git a/roo/src/main/resources/templates/error.html b/spring-roo/src/main/resources/templates/error.html similarity index 100% rename from roo/src/main/resources/templates/error.html rename to spring-roo/src/main/resources/templates/error.html diff --git a/roo/src/main/resources/templates/fragments/footer.html b/spring-roo/src/main/resources/templates/fragments/footer.html similarity index 100% rename from roo/src/main/resources/templates/fragments/footer.html rename to spring-roo/src/main/resources/templates/fragments/footer.html diff --git a/roo/src/main/resources/templates/fragments/header.html b/spring-roo/src/main/resources/templates/fragments/header.html similarity index 100% rename from roo/src/main/resources/templates/fragments/header.html rename to spring-roo/src/main/resources/templates/fragments/header.html diff --git a/roo/src/main/resources/templates/fragments/js/datatables-locale.js b/spring-roo/src/main/resources/templates/fragments/js/datatables-locale.js similarity index 100% rename from roo/src/main/resources/templates/fragments/js/datatables-locale.js rename to spring-roo/src/main/resources/templates/fragments/js/datatables-locale.js diff --git a/roo/src/main/resources/templates/fragments/js/datatables.html b/spring-roo/src/main/resources/templates/fragments/js/datatables.html similarity index 100% rename from roo/src/main/resources/templates/fragments/js/datatables.html rename to spring-roo/src/main/resources/templates/fragments/js/datatables.html diff --git a/roo/src/main/resources/templates/fragments/js/select2.html b/spring-roo/src/main/resources/templates/fragments/js/select2.html similarity index 100% rename from roo/src/main/resources/templates/fragments/js/select2.html rename to spring-roo/src/main/resources/templates/fragments/js/select2.html diff --git a/roo/src/main/resources/templates/fragments/languages.html b/spring-roo/src/main/resources/templates/fragments/languages.html similarity index 100% rename from roo/src/main/resources/templates/fragments/languages.html rename to spring-roo/src/main/resources/templates/fragments/languages.html diff --git a/roo/src/main/resources/templates/fragments/menu.html b/spring-roo/src/main/resources/templates/fragments/menu.html similarity index 100% rename from roo/src/main/resources/templates/fragments/menu.html rename to spring-roo/src/main/resources/templates/fragments/menu.html diff --git a/roo/src/main/resources/templates/fragments/modal-confirm-delete-batch.html b/spring-roo/src/main/resources/templates/fragments/modal-confirm-delete-batch.html similarity index 100% rename from roo/src/main/resources/templates/fragments/modal-confirm-delete-batch.html rename to spring-roo/src/main/resources/templates/fragments/modal-confirm-delete-batch.html diff --git a/roo/src/main/resources/templates/fragments/modal-confirm-delete.html b/spring-roo/src/main/resources/templates/fragments/modal-confirm-delete.html similarity index 100% rename from roo/src/main/resources/templates/fragments/modal-confirm-delete.html rename to spring-roo/src/main/resources/templates/fragments/modal-confirm-delete.html diff --git a/roo/src/main/resources/templates/fragments/modal-confirm.html b/spring-roo/src/main/resources/templates/fragments/modal-confirm.html similarity index 100% rename from roo/src/main/resources/templates/fragments/modal-confirm.html rename to spring-roo/src/main/resources/templates/fragments/modal-confirm.html diff --git a/roo/src/main/resources/templates/fragments/modal-export-empty-error.html b/spring-roo/src/main/resources/templates/fragments/modal-export-empty-error.html similarity index 100% rename from roo/src/main/resources/templates/fragments/modal-export-empty-error.html rename to spring-roo/src/main/resources/templates/fragments/modal-export-empty-error.html diff --git a/roo/src/main/resources/templates/fragments/modal.html b/spring-roo/src/main/resources/templates/fragments/modal.html similarity index 100% rename from roo/src/main/resources/templates/fragments/modal.html rename to spring-roo/src/main/resources/templates/fragments/modal.html diff --git a/roo/src/main/resources/templates/fragments/session-links.html b/spring-roo/src/main/resources/templates/fragments/session-links.html similarity index 100% rename from roo/src/main/resources/templates/fragments/session-links.html rename to spring-roo/src/main/resources/templates/fragments/session-links.html diff --git a/roo/src/main/resources/templates/index.html b/spring-roo/src/main/resources/templates/index.html similarity index 100% rename from roo/src/main/resources/templates/index.html rename to spring-roo/src/main/resources/templates/index.html diff --git a/roo/src/main/resources/templates/layouts/default-layout-no-menu.html b/spring-roo/src/main/resources/templates/layouts/default-layout-no-menu.html similarity index 100% rename from roo/src/main/resources/templates/layouts/default-layout-no-menu.html rename to spring-roo/src/main/resources/templates/layouts/default-layout-no-menu.html diff --git a/roo/src/main/resources/templates/layouts/default-layout.html b/spring-roo/src/main/resources/templates/layouts/default-layout.html similarity index 100% rename from roo/src/main/resources/templates/layouts/default-layout.html rename to spring-roo/src/main/resources/templates/layouts/default-layout.html diff --git a/roo/src/main/resources/templates/layouts/default-list-layout.html b/spring-roo/src/main/resources/templates/layouts/default-list-layout.html similarity index 100% rename from roo/src/main/resources/templates/layouts/default-list-layout.html rename to spring-roo/src/main/resources/templates/layouts/default-list-layout.html diff --git a/roo/src/main/resources/templates/layouts/home-layout.html b/spring-roo/src/main/resources/templates/layouts/home-layout.html similarity index 100% rename from roo/src/main/resources/templates/layouts/home-layout.html rename to spring-roo/src/main/resources/templates/layouts/home-layout.html diff --git a/roo/src/main/resources/templates/login.html b/spring-roo/src/main/resources/templates/login.html similarity index 100% rename from roo/src/main/resources/templates/login.html rename to spring-roo/src/main/resources/templates/login.html diff --git a/roo/src/main/resources/templates/reports/export_default.jrxml b/spring-roo/src/main/resources/templates/reports/export_default.jrxml similarity index 100% rename from roo/src/main/resources/templates/reports/export_default.jrxml rename to spring-roo/src/main/resources/templates/reports/export_default.jrxml diff --git a/spring-security-core/README.md b/spring-security-core/README.md index 0eb506e865..3675e7e160 100644 --- a/spring-security-core/README.md +++ b/spring-security-core/README.md @@ -8,3 +8,4 @@ mvn clean install ### Relevant Articles: - [Intro to @PreFilter and @PostFilter in Spring Security](http://www.baeldung.com/spring-security-prefilter-postfilter) +- [Spring Boot Authentication Auditing Support](http://www.baeldung.com/spring-boot-authentication-audit) diff --git a/spring-security-mvc-custom/pom.xml b/spring-security-mvc-custom/pom.xml index 59339ead5e..46e0dc2b17 100644 --- a/spring-security-mvc-custom/pom.xml +++ b/spring-security-mvc-custom/pom.xml @@ -125,11 +125,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-mvc-digest-auth/pom.xml b/spring-security-mvc-digest-auth/pom.xml index dd772e3343..c0f08c1a2a 100644 --- a/spring-security-mvc-digest-auth/pom.xml +++ b/spring-security-mvc-digest-auth/pom.xml @@ -120,11 +120,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-mvc-login/pom.xml b/spring-security-mvc-login/pom.xml index b3431da7dc..fd67873ff1 100644 --- a/spring-security-mvc-login/pom.xml +++ b/spring-security-mvc-login/pom.xml @@ -117,11 +117,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java b/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java index ea4407c5c4..843f5f4dcd 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java +++ b/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java @@ -6,7 +6,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -14,7 +16,7 @@ import org.springframework.security.web.access.AccessDeniedHandler; public class CustomAccessDeniedHandler implements AccessDeniedHandler { - public static final Logger LOG = Logger.getLogger(CustomAccessDeniedHandler.class); + public static final Logger LOG = LoggerFactory.getLogger(CustomAccessDeniedHandler.class); @Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exc) throws IOException, ServletException { diff --git a/spring-security-mvc-persisted-remember-me/pom.xml b/spring-security-mvc-persisted-remember-me/pom.xml index f215c39c6d..7fc15284f0 100644 --- a/spring-security-mvc-persisted-remember-me/pom.xml +++ b/spring-security-mvc-persisted-remember-me/pom.xml @@ -155,11 +155,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-mvc-session/pom.xml b/spring-security-mvc-session/pom.xml index 3f129c83ba..5255bd3737 100644 --- a/spring-security-mvc-session/pom.xml +++ b/spring-security-mvc-session/pom.xml @@ -125,11 +125,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-rest-basic-auth/pom.xml b/spring-security-rest-basic-auth/pom.xml index 953cfd6b6b..0be9b664e2 100644 --- a/spring-security-rest-basic-auth/pom.xml +++ b/spring-security-rest-basic-auth/pom.xml @@ -172,11 +172,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-rest-custom/pom.xml b/spring-security-rest-custom/pom.xml index d421f8d7b4..0fe642c2b6 100644 --- a/spring-security-rest-custom/pom.xml +++ b/spring-security-rest-custom/pom.xml @@ -177,10 +177,6 @@ jcl-over-slf4j - - org.slf4j - log4j-over-slf4j - diff --git a/spring-security-rest-digest-auth/pom.xml b/spring-security-rest-digest-auth/pom.xml index dc8e12b72b..e2fcd330f5 100644 --- a/spring-security-rest-digest-auth/pom.xml +++ b/spring-security-rest-digest-auth/pom.xml @@ -166,11 +166,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index e7f543a407..d5bd8be52b 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -30,6 +30,10 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Introduction to Spring MVC HandlerInterceptor](http://www.baeldung.com/spring-mvc-handlerinterceptor) - [Using a Custom Spring MVC’s Handler Interceptor to Manage Sessions](http://www.baeldung.com/spring-mvc-custom-handler-interceptor) - [Bootstrap a Web Application with Spring 4](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) +- [REST Query Language – Implementing OR Operation](http://www.baeldung.com/rest-api-query-search-or-operation) + + + ### Build the Project ``` diff --git a/spring-security-rest-full/pom.xml b/spring-security-rest-full/pom.xml index 43d14af5ea..290aa48dea 100644 --- a/spring-security-rest-full/pom.xml +++ b/spring-security-rest-full/pom.xml @@ -226,10 +226,6 @@ jcl-over-slf4j - - org.slf4j - log4j-over-slf4j - diff --git a/spring-security-rest/pom.xml b/spring-security-rest/pom.xml index 996161c721..6052f7d42e 100644 --- a/spring-security-rest/pom.xml +++ b/spring-security-rest/pom.xml @@ -145,11 +145,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - diff --git a/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java b/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java index 9a69528efe..456eeaaeac 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java +++ b/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java @@ -2,7 +2,9 @@ package org.baeldung.web.controller; import java.util.concurrent.Callable; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.baeldung.web.service.AsyncService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; @@ -14,7 +16,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller public class AsyncController { - private static final Logger log = Logger.getLogger(AsyncService.class); + private static final Logger log = LoggerFactory.getLogger(AsyncService.class); @Autowired private AsyncService asyncService; diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java b/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java index fb954a49a7..caaaa8e0dc 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java +++ b/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java @@ -2,7 +2,9 @@ package org.baeldung.web.service; import java.util.concurrent.Callable; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.springframework.scheduling.annotation.Async; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; @@ -10,7 +12,7 @@ import org.springframework.stereotype.Service; @Service public class AsyncServiceImpl implements AsyncService { - private static final Logger log = Logger.getLogger(AsyncService.class); + private static final Logger log = LoggerFactory.getLogger(AsyncService.class); @Async @Override diff --git a/spring-spel/pom.xml b/spring-spel/pom.xml index c3817ce2bd..5bb8480715 100644 --- a/spring-spel/pom.xml +++ b/spring-spel/pom.xml @@ -31,6 +31,12 @@ org.springframework spring-context ${springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/spring-state-machine/README.md b/spring-state-machine/README.md new file mode 100644 index 0000000000..a2668fb650 --- /dev/null +++ b/spring-state-machine/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [A Guide to the Spring State Machine Project](http://www.baeldung.com/spring-state-machine) diff --git a/spring-state-machine/pom.xml b/spring-state-machine/pom.xml index f04d706d47..9dcb51fe4e 100644 --- a/spring-state-machine/pom.xml +++ b/spring-state-machine/pom.xml @@ -24,7 +24,7 @@ org.springframework spring-test - 4.3.7.RELEASE + 4.3.7.RELEASE junit diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index be443e15df..7082441ceb 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -102,11 +102,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - javax.servlet diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index 0f3ed96c4e..58a7cf748f 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -127,6 +127,12 @@ org.springframework spring-core ${org.springframework.version} + + + commons-logging + commons-logging + + org.springframework diff --git a/stripe/.gitignore b/stripe/.gitignore new file mode 100644 index 0000000000..be941a016b --- /dev/null +++ b/stripe/.gitignore @@ -0,0 +1,27 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +### +desktop.ini \ No newline at end of file diff --git a/stripe/pom.xml b/stripe/pom.xml new file mode 100644 index 0000000000..5bb3d4207a --- /dev/null +++ b/stripe/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.baeldung.stripe + stripe + 0.0.1-SNAPSHOT + jar + + Stripe + Demo project for Stripe API + + + org.springframework.boot + spring-boot-starter-parent + 1.5.2.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + org.projectlombok + lombok + 1.16.16 + + + + com.stripe + stripe-java + 4.2.0 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/stripe/src/main/java/com/baeldung/stripe/ChargeController.java b/stripe/src/main/java/com/baeldung/stripe/ChargeController.java new file mode 100644 index 0000000000..cd3f057cd8 --- /dev/null +++ b/stripe/src/main/java/com/baeldung/stripe/ChargeController.java @@ -0,0 +1,38 @@ +package com.baeldung.stripe; + +import com.baeldung.stripe.ChargeRequest.Currency; +import com.stripe.exception.StripeException; +import com.stripe.model.Charge; +import lombok.extern.java.Log; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RequestMapping; +import static org.springframework.web.bind.annotation.RequestMethod.POST; + +@Log +@Controller +public class ChargeController { + + @Autowired + StripeService paymentsService; + + @RequestMapping(value = "/charge", method = POST) + public String charge(ChargeRequest chargeRequest, Model model) throws StripeException { + chargeRequest.setDescription("Example charge"); + chargeRequest.setCurrency(Currency.EUR); + Charge charge = paymentsService.charge(chargeRequest); + model.addAttribute("id", charge.getId()); + model.addAttribute("status", charge.getStatus()); + model.addAttribute("chargeId", charge.getId()); + model.addAttribute("balance_transaction", charge.getBalanceTransaction()); + return "result"; + } + + @ExceptionHandler(StripeException.class) + public String handleError(Model model, StripeException ex) { + model.addAttribute("error", ex.getMessage()); + return "result"; + } +} diff --git a/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java b/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java new file mode 100644 index 0000000000..76cdea7bb4 --- /dev/null +++ b/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java @@ -0,0 +1,20 @@ +package com.baeldung.stripe; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString(includeFieldNames = false) +public class ChargeRequest { + + public enum Currency { + EUR, USD; + } + private String description; + private int amount; // cents + private Currency currency; + private String stripeEmail; + private String stripeToken; +} diff --git a/stripe/src/main/java/com/baeldung/stripe/CheckoutController.java b/stripe/src/main/java/com/baeldung/stripe/CheckoutController.java new file mode 100644 index 0000000000..2d525843b0 --- /dev/null +++ b/stripe/src/main/java/com/baeldung/stripe/CheckoutController.java @@ -0,0 +1,21 @@ +package com.baeldung.stripe; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class CheckoutController { + + @Value("${STRIPE_PUBLIC_KEY}") + private String stripePublicKey; + + @RequestMapping("/checkout") + public String checkout(Model model) { + model.addAttribute("amount", 50 * 100); // in cents + model.addAttribute("stripePublicKey", stripePublicKey); + model.addAttribute("currency", ChargeRequest.Currency.EUR); + return "checkout"; + } +} diff --git a/stripe/src/main/java/com/baeldung/stripe/StripeApplication.java b/stripe/src/main/java/com/baeldung/stripe/StripeApplication.java new file mode 100644 index 0000000000..735c67dda5 --- /dev/null +++ b/stripe/src/main/java/com/baeldung/stripe/StripeApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.stripe; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class StripeApplication { + + public static void main(String[] args) { + SpringApplication.run(StripeApplication.class, args); + } +} diff --git a/stripe/src/main/java/com/baeldung/stripe/StripeService.java b/stripe/src/main/java/com/baeldung/stripe/StripeService.java new file mode 100644 index 0000000000..8784b604c2 --- /dev/null +++ b/stripe/src/main/java/com/baeldung/stripe/StripeService.java @@ -0,0 +1,36 @@ +package com.baeldung.stripe; + +import com.stripe.Stripe; +import com.stripe.exception.APIConnectionException; +import com.stripe.exception.APIException; +import com.stripe.exception.AuthenticationException; +import com.stripe.exception.CardException; +import com.stripe.exception.InvalidRequestException; +import com.stripe.model.Charge; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class StripeService { + + @Value("${STRIPE_SECRET_KEY}") + String secretKey; + + @PostConstruct + public void init() { + Stripe.apiKey = secretKey; + } + + public Charge charge(ChargeRequest chargeRequest) + throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException { + Map chargeParams = new HashMap<>(); + chargeParams.put("amount", chargeRequest.getAmount()); + chargeParams.put("currency", chargeRequest.getCurrency()); + chargeParams.put("description", chargeRequest.getDescription()); + chargeParams.put("source", chargeRequest.getStripeToken()); + return Charge.create(chargeParams); + } +} diff --git a/stripe/src/main/resources/static/index.html b/stripe/src/main/resources/static/index.html new file mode 100644 index 0000000000..090a01e91d --- /dev/null +++ b/stripe/src/main/resources/static/index.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/stripe/src/main/resources/templates/checkout.html b/stripe/src/main/resources/templates/checkout.html new file mode 100644 index 0000000000..4af336ce99 --- /dev/null +++ b/stripe/src/main/resources/templates/checkout.html @@ -0,0 +1,35 @@ + + + + Checkout + + + +
+ + + + +
+ + diff --git a/stripe/src/main/resources/templates/result.html b/stripe/src/main/resources/templates/result.html new file mode 100644 index 0000000000..57f02b74a4 --- /dev/null +++ b/stripe/src/main/resources/templates/result.html @@ -0,0 +1,17 @@ + + + + Result + + +

+
+

Success!

+
Id.:
+
Status:
+
Charge id.:
+
Balance transaction id.:
+
+ Checkout again + + diff --git a/struts2/pom.xml b/struts2/pom.xml index ca5a682f9d..e9c321f908 100644 --- a/struts2/pom.xml +++ b/struts2/pom.xml @@ -63,6 +63,12 @@ org.springframework spring-core 4.3.6.RELEASE + + + commons-logging + commons-logging + +
\ No newline at end of file diff --git a/testng/README.md b/testng/README.md new file mode 100644 index 0000000000..0e3586c9f3 --- /dev/null +++ b/testng/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Introduction to TestNG](http://www.baeldung.com/testng) diff --git a/vertx/README.md b/vertx/README.md new file mode 100644 index 0000000000..e710df362d --- /dev/null +++ b/vertx/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Introduction to Vert.x](http://www.baeldung.com/vertx) diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index e321544d4e..c4c66ddb44 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -93,6 +93,12 @@ rest-assured 3.0.1 test + + + commons-logging + commons-logging + +
@@ -151,12 +157,6 @@ ${org.slf4j.version} - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - - diff --git a/xml/README.md b/xml/README.md index 8531f8b063..320089b088 100644 --- a/xml/README.md +++ b/xml/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Intro to XPath with Java](http://www.baeldung.com/java-xpath) +- [Introduction to JiBX](http://www.baeldung.com/jibx)