results = movieRepository.findByDirectorNotLike("An%");
+ assertEquals(5, results.size());
+ }
+}
diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/test-movie-cleanup.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/test-movie-cleanup.sql
new file mode 100644
index 0000000000..90aa15307c
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/resources/test-movie-cleanup.sql
@@ -0,0 +1 @@
+DELETE FROM Movie;
\ No newline at end of file
diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/test-movie-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/test-movie-data.sql
new file mode 100644
index 0000000000..37f8e4fe64
--- /dev/null
+++ b/persistence-modules/spring-data-jpa-2/src/test/resources/test-movie-data.sql
@@ -0,0 +1,7 @@
+INSERT INTO movie(id, title, director, rating, duration) VALUES(1, 'Godzilla: King of the Monsters', ' Michael Dougherty', 'PG-13', 132);
+INSERT INTO movie(id, title, director, rating, duration) VALUES(2, 'Avengers: Endgame', 'Anthony Russo', 'PG-13', 181);
+INSERT INTO movie(id, title, director, rating, duration) VALUES(3, 'Captain Marvel', 'Anna Boden', 'PG-13', 123);
+INSERT INTO movie(id, title, director, rating, duration) VALUES(4, 'Dumbo', 'Tim Burton', 'PG', 112);
+INSERT INTO movie(id, title, director, rating, duration) VALUES(5, 'Booksmart', 'Olivia Wilde', 'R', 102);
+INSERT INTO movie(id, title, director, rating, duration) VALUES(6, 'Aladdin', 'Guy Ritchie', 'PG', 128);
+INSERT INTO movie(id, title, director, rating, duration) VALUES(7, 'The Sun Is Also a Star', 'Ry Russo-Young', 'PG-13', 100);
diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java
index 8ff6799e31..3b9aa2cc18 100644
--- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java
+++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java
@@ -9,6 +9,6 @@ public class MultipleDbApplication {
public static void main(String[] args) {
SpringApplication.run(MultipleDbApplication.class, args);
}
-
+
}
diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java
new file mode 100644
index 0000000000..a6f8f0829f
--- /dev/null
+++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java
@@ -0,0 +1,71 @@
+package com.baeldung.multipledb;
+
+import java.util.HashMap;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+
+/**
+ * By default, the persistence-multiple-db.properties file is read for
+ * non auto configuration in PersistenceProductConfiguration.
+ *
+ * If we need to use persistence-multiple-db-boot.properties and auto configuration
+ * then uncomment the below @Configuration class and comment out PersistenceProductConfiguration.
+ */
+//@Configuration
+@PropertySource({"classpath:persistence-multiple-db-boot.properties"})
+@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager")
+@Profile("!tc")
+public class PersistenceProductAutoConfiguration {
+ @Autowired
+ private Environment env;
+
+ public PersistenceProductAutoConfiguration() {
+ super();
+ }
+
+ //
+
+ @Bean
+ public LocalContainerEntityManagerFactoryBean productEntityManager() {
+ final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
+ em.setDataSource(productDataSource());
+ em.setPackagesToScan("com.baeldung.multipledb.model.product");
+
+ final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
+ em.setJpaVendorAdapter(vendorAdapter);
+ final HashMap properties = new HashMap();
+ properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
+ properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
+ em.setJpaPropertyMap(properties);
+
+ return em;
+ }
+
+ @Bean
+ @ConfigurationProperties(prefix="spring.second-datasource")
+ public DataSource productDataSource() {
+ return DataSourceBuilder.create().build();
+ }
+
+ @Bean
+ public PlatformTransactionManager productTransactionManager() {
+ final JpaTransactionManager transactionManager = new JpaTransactionManager();
+ transactionManager.setEntityManagerFactory(productEntityManager().getObject());
+ return transactionManager;
+ }
+
+}
diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java
new file mode 100644
index 0000000000..e04a1621b2
--- /dev/null
+++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java
@@ -0,0 +1,75 @@
+package com.baeldung.multipledb;
+
+import java.util.HashMap;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.context.annotation.Profile;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+
+/**
+ * By default, the persistence-multiple-db.properties file is read for
+ * non auto configuration in PersistenceUserConfiguration.
+ *
+ * If we need to use persistence-multiple-db-boot.properties and auto configuration
+ * then uncomment the below @Configuration class and comment out PersistenceUserConfiguration.
+ */
+//@Configuration
+@PropertySource({"classpath:persistence-multiple-db-boot.properties"})
+@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager")
+@Profile("!tc")
+public class PersistenceUserAutoConfiguration {
+ @Autowired
+ private Environment env;
+
+ public PersistenceUserAutoConfiguration() {
+ super();
+ }
+
+ //
+
+ @Primary
+ @Bean
+ public LocalContainerEntityManagerFactoryBean userEntityManager() {
+ final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
+ em.setDataSource(userDataSource());
+ em.setPackagesToScan("com.baeldung.multipledb.model.user");
+
+ final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
+ em.setJpaVendorAdapter(vendorAdapter);
+ final HashMap properties = new HashMap();
+ properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
+ properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
+ em.setJpaPropertyMap(properties);
+
+ return em;
+ }
+
+ @Bean
+ @Primary
+ @ConfigurationProperties(prefix="spring.datasource")
+ public DataSource userDataSource() {
+ return DataSourceBuilder.create().build();
+ }
+
+ @Primary
+ @Bean
+ public PlatformTransactionManager userTransactionManager() {
+ final JpaTransactionManager transactionManager = new JpaTransactionManager();
+ transactionManager.setEntityManagerFactory(userEntityManager().getObject());
+ return transactionManager;
+ }
+
+}
diff --git a/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties b/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties
new file mode 100644
index 0000000000..ffca79b3f5
--- /dev/null
+++ b/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties
@@ -0,0 +1,11 @@
+hibernate.hbm2ddl.auto=create-drop
+hibernate.cache.use_second_level_cache=false
+hibernate.cache.use_query_cache=false
+
+spring.datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
+spring.datasource.username=sa
+spring.datasource.password=sa
+
+spring.second-datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
+spring.second-datasource.username=sa
+spring.second-datasource.password=sa
diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
index bcc4103d08..6ba10a4d49 100644
--- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
+++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java
@@ -12,7 +12,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
diff --git a/persistence-modules/spring-persistence-simple/README.md b/persistence-modules/spring-persistence-simple/README.md
index c656efaa3b..c408ff3c96 100644
--- a/persistence-modules/spring-persistence-simple/README.md
+++ b/persistence-modules/spring-persistence-simple/README.md
@@ -11,6 +11,7 @@
- [Transactions with Spring and JPA](https://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
- [Introduction to Spring Data JPA](http://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
- [Spring Data JPA @Query](http://www.baeldung.com/spring-data-jpa-query)
+- [Spring JDBC](https://www.baeldung.com/spring-jdbc-jdbctemplate)
### Eclipse Config
diff --git a/persistence-modules/spring-persistence-simple/pom.xml b/persistence-modules/spring-persistence-simple/pom.xml
index 5f48b267b5..1afacab164 100644
--- a/persistence-modules/spring-persistence-simple/pom.xml
+++ b/persistence-modules/spring-persistence-simple/pom.xml
@@ -18,12 +18,6 @@
org.springframework
spring-orm
${org.springframework.version}
-
-
- commons-logging
- commons-logging
-
-
org.springframework
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/config/PersistenceConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java
similarity index 93%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/config/PersistenceConfig.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java
index c454ab3b54..569971e311 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/config/PersistenceConfig.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceConfig.java
@@ -1,11 +1,10 @@
-package org.baeldung.config;
+package com.baeldung.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
-import org.baeldung.persistence.dao.IFooDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -24,15 +23,16 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-import com.baeldung.persistence.dao.impl.FooDao;
+import com.baeldung.hibernate.dao.FooDao;
+import com.baeldung.jpa.dao.IFooDao;
import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
-@EnableJpaRepositories(basePackages = { "com.baeldung.persistence" }, transactionManagerRef = "jpaTransactionManager")
+@EnableJpaRepositories(basePackages = { "com.baeldung.hibernate.dao" }, transactionManagerRef = "jpaTransactionManager")
@EnableJpaAuditing
@PropertySource({ "classpath:persistence-mysql.properties" })
-@ComponentScan({ "com.baeldung.persistence" })
+@ComponentScan({ "com.baeldung.persistence", "com.baeldung.hibernate.dao" })
public class PersistenceConfig {
@Autowired
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/config/PersistenceJPAConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java
similarity index 93%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/config/PersistenceJPAConfig.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java
index ec0d4bca3c..9fae34d99e 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/config/PersistenceJPAConfig.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/config/PersistenceJPAConfig.java
@@ -1,4 +1,4 @@
-package org.baeldung.config;
+package com.baeldung.config;
import java.util.Properties;
@@ -25,8 +25,8 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
-@ComponentScan({ "org.baeldung.persistence" })
-@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
+@ComponentScan({ "com.baeldung.persistence","com.baeldung.jpa.dao" })
+@EnableJpaRepositories(basePackages = "com.baeldung.jpa.dao")
public class PersistenceJPAConfig {
@Autowired
@@ -42,7 +42,7 @@ public class PersistenceJPAConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
+ em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/impl/FooDao.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/hibernate/dao/FooDao.java
similarity index 69%
rename from persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/impl/FooDao.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/hibernate/dao/FooDao.java
index 2d940527e1..67c10fe7fe 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/impl/FooDao.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/hibernate/dao/FooDao.java
@@ -1,9 +1,9 @@
-package com.baeldung.persistence.dao.impl;
+package com.baeldung.hibernate.dao;
-import org.baeldung.persistence.dao.IFooDao;
-import org.baeldung.persistence.model.Foo;
+import com.baeldung.persistence.model.Foo;
import org.springframework.stereotype.Repository;
+import com.baeldung.jpa.dao.IFooDao;
import com.baeldung.persistence.dao.common.AbstractHibernateDao;
@Repository
diff --git a/spring-all/src/main/java/org/baeldung/jdbc/CustomSQLErrorCodeTranslator.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/CustomSQLErrorCodeTranslator.java
similarity index 88%
rename from spring-all/src/main/java/org/baeldung/jdbc/CustomSQLErrorCodeTranslator.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/CustomSQLErrorCodeTranslator.java
index 8a02fe6a53..48ddfb04b1 100644
--- a/spring-all/src/main/java/org/baeldung/jdbc/CustomSQLErrorCodeTranslator.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/CustomSQLErrorCodeTranslator.java
@@ -1,4 +1,4 @@
-package org.baeldung.jdbc;
+package com.baeldung.jdbc;
import java.sql.SQLException;
@@ -10,7 +10,7 @@ public class CustomSQLErrorCodeTranslator extends SQLErrorCodeSQLExceptionTransl
@Override
protected DataAccessException customTranslate(final String task, final String sql, final SQLException sqlException) {
- if (sqlException.getErrorCode() == -104) {
+ if (sqlException.getErrorCode() == 23505) {
return new DuplicateKeyException("Custome Exception translator - Integrity contraint voilation.", sqlException);
}
return null;
diff --git a/spring-all/src/main/java/org/baeldung/jdbc/Employee.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/Employee.java
similarity index 96%
rename from spring-all/src/main/java/org/baeldung/jdbc/Employee.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/Employee.java
index e9408eb7fa..a43eb265c7 100644
--- a/spring-all/src/main/java/org/baeldung/jdbc/Employee.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/Employee.java
@@ -1,4 +1,4 @@
-package org.baeldung.jdbc;
+package com.baeldung.jdbc;
public class Employee {
private int id;
diff --git a/spring-all/src/main/java/org/baeldung/jdbc/EmployeeDAO.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/EmployeeDAO.java
similarity index 99%
rename from spring-all/src/main/java/org/baeldung/jdbc/EmployeeDAO.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/EmployeeDAO.java
index 1f0e7b28ad..9ba4ebdb6d 100644
--- a/spring-all/src/main/java/org/baeldung/jdbc/EmployeeDAO.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/EmployeeDAO.java
@@ -1,4 +1,4 @@
-package org.baeldung.jdbc;
+package com.baeldung.jdbc;
import java.sql.PreparedStatement;
import java.sql.SQLException;
diff --git a/spring-all/src/main/java/org/baeldung/jdbc/EmployeeRowMapper.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/EmployeeRowMapper.java
similarity index 95%
rename from spring-all/src/main/java/org/baeldung/jdbc/EmployeeRowMapper.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/EmployeeRowMapper.java
index f926836c40..d09cd45dbc 100644
--- a/spring-all/src/main/java/org/baeldung/jdbc/EmployeeRowMapper.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/EmployeeRowMapper.java
@@ -1,4 +1,4 @@
-package org.baeldung.jdbc;
+package com.baeldung.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
diff --git a/spring-all/src/main/java/org/baeldung/jdbc/config/SpringJdbcConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/config/SpringJdbcConfig.java
similarity index 84%
rename from spring-all/src/main/java/org/baeldung/jdbc/config/SpringJdbcConfig.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/config/SpringJdbcConfig.java
index f7eb592366..ddc24e439f 100644
--- a/spring-all/src/main/java/org/baeldung/jdbc/config/SpringJdbcConfig.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jdbc/config/SpringJdbcConfig.java
@@ -1,4 +1,4 @@
-package org.baeldung.jdbc.config;
+package com.baeldung.jdbc.config;
import javax.sql.DataSource;
@@ -10,12 +10,12 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
@Configuration
-@ComponentScan("org.baeldung.jdbc")
+@ComponentScan("com.baeldung.jdbc")
public class SpringJdbcConfig {
@Bean
public DataSource dataSource() {
- return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).addScript("classpath:jdbc/schema.sql").addScript("classpath:jdbc/test-data.sql").build();
+ return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("classpath:jdbc/schema.sql").addScript("classpath:jdbc/test-data.sql").build();
}
// @Bean
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/AbstractJpaDAO.java
similarity index 96%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/AbstractJpaDAO.java
index decca35c08..4fbc8464bb 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/AbstractJpaDAO.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/AbstractJpaDAO.java
@@ -1,4 +1,4 @@
-package org.baeldung.persistence.dao;
+package com.baeldung.jpa.dao;
import java.io.Serializable;
import java.util.List;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/FooDao.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/FooDao.java
similarity index 73%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/FooDao.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/FooDao.java
index 77978c5cf2..e79a44a0c2 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/FooDao.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/FooDao.java
@@ -1,6 +1,6 @@
-package org.baeldung.persistence.dao;
+package com.baeldung.jpa.dao;
-import org.baeldung.persistence.model.Foo;
+import com.baeldung.persistence.model.Foo;
import org.springframework.stereotype.Repository;
@Repository
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/IFooDao.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/IFooDao.java
similarity index 74%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/IFooDao.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/IFooDao.java
index ba188b9b3a..8140c56edd 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/dao/IFooDao.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/jpa/dao/IFooDao.java
@@ -1,8 +1,8 @@
-package org.baeldung.persistence.dao;
+package com.baeldung.jpa.dao;
import java.util.List;
-import org.baeldung.persistence.model.Foo;
+import com.baeldung.persistence.model.Foo;
public interface IFooDao {
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/common/GenericJpaDao.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/common/GenericJpaDao.java
index 5bcebed761..d4da194f4d 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/common/GenericJpaDao.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/dao/common/GenericJpaDao.java
@@ -2,11 +2,12 @@ package com.baeldung.persistence.dao.common;
import java.io.Serializable;
-import org.baeldung.persistence.dao.AbstractJpaDAO;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
+import com.baeldung.jpa.dao.AbstractJpaDAO;
+
@Repository
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class GenericJpaDao extends AbstractJpaDAO implements IGenericDao {
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/model/Bar.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/model/Bar.java
similarity index 98%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/model/Bar.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/model/Bar.java
index b602e57562..5a88ecc6cf 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/model/Bar.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/model/Bar.java
@@ -1,4 +1,4 @@
-package org.baeldung.persistence.model;
+package com.baeldung.persistence.model;
import java.io.Serializable;
import java.util.List;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/model/Foo.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/model/Foo.java
similarity index 98%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/model/Foo.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/model/Foo.java
index 30635e9ef2..009876f8cb 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/model/Foo.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/model/Foo.java
@@ -1,4 +1,4 @@
-package org.baeldung.persistence.model;
+package com.baeldung.persistence.model;
import java.io.Serializable;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/service/FooService.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/service/FooService.java
similarity index 81%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/service/FooService.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/service/FooService.java
index 6d1bb0adbe..efe9743670 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/persistence/service/FooService.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/persistence/service/FooService.java
@@ -1,9 +1,9 @@
-package org.baeldung.persistence.service;
+package com.baeldung.persistence.service;
import java.util.List;
-import org.baeldung.persistence.dao.IFooDao;
-import org.baeldung.persistence.model.Foo;
+import com.baeldung.jpa.dao.IFooDao;
+import com.baeldung.persistence.model.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/config/PersistenceConfig.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java
similarity index 93%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/config/PersistenceConfig.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java
index 067bac2018..717b9c3aa0 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/config/PersistenceConfig.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/config/PersistenceConfig.java
@@ -1,4 +1,4 @@
-package org.baeldung.spring.data.persistence.config;
+package com.baeldung.spring.data.persistence.config;
import java.util.Properties;
@@ -24,9 +24,9 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-${envTarget:h2}.properties" })
-@ComponentScan({ "org.baeldung.spring.data.persistence" })
+@ComponentScan({ "com.baeldung.spring.data.persistence" })
// @ImportResource("classpath*:springDataPersistenceConfig.xml")
-@EnableJpaRepositories(basePackages = "org.baeldung.spring.data.persistence.dao")
+@EnableJpaRepositories(basePackages = "com.baeldung.spring.data.persistence.dao")
public class PersistenceConfig {
@Autowired
@@ -40,7 +40,7 @@ public class PersistenceConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] { "org.baeldung.spring.data.persistence.model" });
+ em.setPackagesToScan(new String[] { "com.baeldung.spring.data.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
// vendorAdapter.set
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/IFooDao.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/IFooDao.java
similarity index 77%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/IFooDao.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/IFooDao.java
index 2f74096e14..d2b746dc8b 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/IFooDao.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/IFooDao.java
@@ -1,6 +1,6 @@
-package org.baeldung.spring.data.persistence.dao;
+package com.baeldung.spring.data.persistence.dao;
-import org.baeldung.spring.data.persistence.model.Foo;
+import com.baeldung.spring.data.persistence.model.Foo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepository.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepository.java
similarity index 97%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepository.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepository.java
index 4d01376af7..e8f95302ef 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepository.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepository.java
@@ -1,11 +1,11 @@
-package org.baeldung.spring.data.persistence.dao.user;
+package com.baeldung.spring.data.persistence.dao.user;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
-import org.baeldung.spring.data.persistence.model.User;
+import com.baeldung.spring.data.persistence.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepositoryCustom.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepositoryCustom.java
similarity index 72%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepositoryCustom.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepositoryCustom.java
index 1a874fb5e5..ff92159077 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepositoryCustom.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepositoryCustom.java
@@ -1,11 +1,11 @@
-package org.baeldung.spring.data.persistence.dao.user;
+package com.baeldung.spring.data.persistence.dao.user;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
-import org.baeldung.spring.data.persistence.model.User;
+import com.baeldung.spring.data.persistence.model.User;
public interface UserRepositoryCustom {
List findUserByEmails(Set emails);
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepositoryCustomImpl.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepositoryCustomImpl.java
similarity index 94%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepositoryCustomImpl.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepositoryCustomImpl.java
index c28050401c..8bd8217e83 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/dao/user/UserRepositoryCustomImpl.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/dao/user/UserRepositoryCustomImpl.java
@@ -1,4 +1,4 @@
-package org.baeldung.spring.data.persistence.dao.user;
+package com.baeldung.spring.data.persistence.dao.user;
import java.util.ArrayList;
import java.util.Collection;
@@ -15,7 +15,7 @@ import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
-import org.baeldung.spring.data.persistence.model.User;
+import com.baeldung.spring.data.persistence.model.User;
public class UserRepositoryCustomImpl implements UserRepositoryCustom {
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/Foo.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/Foo.java
similarity index 96%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/Foo.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/Foo.java
index 8f316ac55b..64bfe203d0 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/Foo.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/Foo.java
@@ -1,4 +1,4 @@
-package org.baeldung.spring.data.persistence.model;
+package com.baeldung.spring.data.persistence.model;
import java.io.Serializable;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/Possession.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/Possession.java
similarity index 97%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/Possession.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/Possession.java
index da64e78552..44ca9fc62e 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/Possession.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/Possession.java
@@ -1,4 +1,4 @@
-package org.baeldung.spring.data.persistence.model;
+package com.baeldung.spring.data.persistence.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/User.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java
similarity index 98%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/User.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java
index 486ed046e5..09f1092644 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/model/User.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/model/User.java
@@ -1,4 +1,4 @@
-package org.baeldung.spring.data.persistence.model;
+package com.baeldung.spring.data.persistence.model;
import javax.persistence.*;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/IFooService.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/IFooService.java
similarity index 58%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/IFooService.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/IFooService.java
index 26d0171551..00e7ac01e4 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/IFooService.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/IFooService.java
@@ -1,6 +1,6 @@
-package org.baeldung.spring.data.persistence.service;
+package com.baeldung.spring.data.persistence.service;
-import org.baeldung.spring.data.persistence.model.Foo;
+import com.baeldung.spring.data.persistence.model.Foo;
import com.baeldung.persistence.dao.common.IOperations;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/common/AbstractService.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/common/AbstractService.java
similarity index 95%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/common/AbstractService.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/common/AbstractService.java
index cf28d5e5c6..61c7d6fcaa 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/common/AbstractService.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/common/AbstractService.java
@@ -1,4 +1,4 @@
-package org.baeldung.spring.data.persistence.service.common;
+package com.baeldung.spring.data.persistence.service.common;
import java.io.Serializable;
import java.util.List;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/impl/FooService.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java
similarity index 70%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/impl/FooService.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java
index b7ed496df1..cd566ba9f6 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/spring/data/persistence/service/impl/FooService.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/spring/data/persistence/service/impl/FooService.java
@@ -1,10 +1,10 @@
-package org.baeldung.spring.data.persistence.service.impl;
+package com.baeldung.spring.data.persistence.service.impl;
-import org.baeldung.spring.data.persistence.model.Foo;
-import org.baeldung.spring.data.persistence.dao.IFooDao;
-import org.baeldung.spring.data.persistence.service.IFooService;
-import org.baeldung.spring.data.persistence.service.common.AbstractService;
+import com.baeldung.spring.data.persistence.model.Foo;
+import com.baeldung.spring.data.persistence.dao.IFooDao;
+import com.baeldung.spring.data.persistence.service.IFooService;
+import com.baeldung.spring.data.persistence.service.common.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
diff --git a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/util/IDUtil.java b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/util/IDUtil.java
similarity index 96%
rename from persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/util/IDUtil.java
rename to persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/util/IDUtil.java
index 85ab623e5f..45e72e046d 100644
--- a/persistence-modules/spring-persistence-simple/src/main/java/org/baeldung/util/IDUtil.java
+++ b/persistence-modules/spring-persistence-simple/src/main/java/com/baeldung/util/IDUtil.java
@@ -1,4 +1,4 @@
-package org.baeldung.util;
+package com.baeldung.util;
import java.util.Random;
diff --git a/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/schema.sql b/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/schema.sql
new file mode 100644
index 0000000000..c86d35cdae
--- /dev/null
+++ b/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/schema.sql
@@ -0,0 +1,7 @@
+CREATE TABLE EMPLOYEE
+(
+ ID int NOT NULL PRIMARY KEY,
+ FIRST_NAME varchar(255),
+ LAST_NAME varchar(255),
+ ADDRESS varchar(255),
+);
\ No newline at end of file
diff --git a/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/springJdbc-config.xml b/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/springJdbc-config.xml
new file mode 100644
index 0000000000..e3d7452eb1
--- /dev/null
+++ b/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/springJdbc-config.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/test-data.sql b/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/test-data.sql
new file mode 100644
index 0000000000..b9ef8fec25
--- /dev/null
+++ b/persistence-modules/spring-persistence-simple/src/main/resources/jdbc/test-data.sql
@@ -0,0 +1,7 @@
+INSERT INTO EMPLOYEE VALUES (1, 'James', 'Gosling', 'Canada');
+
+INSERT INTO EMPLOYEE VALUES (2, 'Donald', 'Knuth', 'USA');
+
+INSERT INTO EMPLOYEE VALUES (3, 'Linus', 'Torvalds', 'Finland');
+
+INSERT INTO EMPLOYEE VALUES (4, 'Dennis', 'Ritchie', 'USA');
\ No newline at end of file
diff --git a/persistence-modules/spring-persistence-simple/src/main/resources/persistence.xml b/persistence-modules/spring-persistence-simple/src/main/resources/persistence.xml
index 6304fa0a65..57687c306d 100644
--- a/persistence-modules/spring-persistence-simple/src/main/resources/persistence.xml
+++ b/persistence-modules/spring-persistence-simple/src/main/resources/persistence.xml
@@ -11,7 +11,7 @@
-
+
- 2.21.0
+ 2.22.0
3.7.0
1.6.0
1.8
@@ -1549,8 +1548,8 @@
1.2
2.9.8
1.3
- 1.2.0
- 5.2.0
+ 1.4.2
+ 5.4.2
0.3.1
2.5.1
0.0.1
diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml
index 3306fd1729..c1f537d2fe 100644
--- a/spring-5-webflux/pom.xml
+++ b/spring-5-webflux/pom.xml
@@ -28,12 +28,22 @@
+
+ 1.8
+ 2.2.0.M3
+
+
org.springframework.boot
spring-boot-starter-webflux
+
+ org.springframework.boot
+ spring-boot-starter-rsocket
+
+
org.projectlombok
lombok
@@ -46,8 +56,8 @@
- junit
- junit
+ io.projectreactor
+ reactor-test
test
@@ -60,4 +70,35 @@
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/snapshot
+
+ true
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/milestone
+
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/snapshot
+
+ true
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/milestone
+
+
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/ClientApplication.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/ClientApplication.java
new file mode 100644
index 0000000000..6f35ec5ee0
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/ClientApplication.java
@@ -0,0 +1,16 @@
+package com.baeldung.spring.rsocket.client;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+
+@SpringBootApplication
+public class ClientApplication {
+
+ public static void main(String[] args) {
+ new SpringApplicationBuilder()
+ .main(ClientApplication.class)
+ .sources(ClientApplication.class)
+ .profiles("client")
+ .run(args);
+ }
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/ClientConfiguration.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/ClientConfiguration.java
new file mode 100644
index 0000000000..7dd3591cd6
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/ClientConfiguration.java
@@ -0,0 +1,30 @@
+package com.baeldung.spring.rsocket.client;
+
+import io.rsocket.RSocket;
+import io.rsocket.RSocketFactory;
+import io.rsocket.frame.decoder.PayloadDecoder;
+import io.rsocket.transport.netty.client.TcpClientTransport;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.messaging.rsocket.RSocketRequester;
+import org.springframework.messaging.rsocket.RSocketStrategies;
+import org.springframework.util.MimeTypeUtils;
+
+@Configuration
+public class ClientConfiguration {
+
+ @Bean
+ public RSocket rSocket() {
+ return RSocketFactory.connect()
+ .mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE)
+ .frameDecoder(PayloadDecoder.ZERO_COPY)
+ .transport(TcpClientTransport.create(7000))
+ .start()
+ .block();
+ }
+
+ @Bean
+ RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
+ return RSocketRequester.wrap(rSocket(), MimeTypeUtils.APPLICATION_JSON, rSocketStrategies);
+ }
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/MarketDataRestController.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/MarketDataRestController.java
new file mode 100644
index 0000000000..3701bd69e9
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/client/MarketDataRestController.java
@@ -0,0 +1,47 @@
+package com.baeldung.spring.rsocket.client;
+
+import com.baeldung.spring.rsocket.model.MarketData;
+import com.baeldung.spring.rsocket.model.MarketDataRequest;
+import java.util.Random;
+import org.reactivestreams.Publisher;
+import org.springframework.http.MediaType;
+import org.springframework.messaging.rsocket.RSocketRequester;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class MarketDataRestController {
+
+ private final Random random = new Random();
+ private final RSocketRequester rSocketRequester;
+
+ public MarketDataRestController(RSocketRequester rSocketRequester) {
+ this.rSocketRequester = rSocketRequester;
+ }
+
+ @GetMapping(value = "/current/{stock}")
+ public Publisher current(@PathVariable("stock") String stock) {
+ return rSocketRequester.route("currentMarketData")
+ .data(new MarketDataRequest(stock))
+ .retrieveMono(MarketData.class);
+ }
+
+ @GetMapping(value = "/feed/{stock}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
+ public Publisher feed(@PathVariable("stock") String stock) {
+ return rSocketRequester.route("feedMarketData")
+ .data(new MarketDataRequest(stock))
+ .retrieveFlux(MarketData.class);
+ }
+
+ @GetMapping(value = "/collect")
+ public Publisher collect() {
+ return rSocketRequester.route("collectMarketData")
+ .data(getMarketData())
+ .send();
+ }
+
+ private MarketData getMarketData() {
+ return new MarketData("X", random.nextInt(10));
+ }
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/model/MarketData.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/model/MarketData.java
new file mode 100644
index 0000000000..3eeaf449e9
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/model/MarketData.java
@@ -0,0 +1,20 @@
+package com.baeldung.spring.rsocket.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class MarketData {
+
+ private String stock;
+ private int currentPrice;
+
+ public static MarketData fromException(Exception e) {
+ MarketData marketData = new MarketData();
+ marketData.setStock(e.getMessage());
+ return marketData;
+ }
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/model/MarketDataRequest.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/model/MarketDataRequest.java
new file mode 100644
index 0000000000..1debbb0870
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/model/MarketDataRequest.java
@@ -0,0 +1,13 @@
+package com.baeldung.spring.rsocket.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class MarketDataRequest {
+
+ private String stock;
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/MarketDataRSocketController.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/MarketDataRSocketController.java
new file mode 100644
index 0000000000..1ff23966fa
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/MarketDataRSocketController.java
@@ -0,0 +1,40 @@
+package com.baeldung.spring.rsocket.server;
+
+import com.baeldung.spring.rsocket.model.MarketData;
+import com.baeldung.spring.rsocket.model.MarketDataRequest;
+import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
+import org.springframework.messaging.handler.annotation.MessageMapping;
+import org.springframework.stereotype.Controller;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+@Controller
+public class MarketDataRSocketController {
+
+ private final MarketDataRepository marketDataRepository;
+
+ public MarketDataRSocketController(MarketDataRepository marketDataRepository) {
+ this.marketDataRepository = marketDataRepository;
+ }
+
+ @MessageMapping("currentMarketData")
+ public Mono currentMarketData(MarketDataRequest marketDataRequest) {
+ return marketDataRepository.getOne(marketDataRequest.getStock());
+ }
+
+ @MessageMapping("feedMarketData")
+ public Flux feedMarketData(MarketDataRequest marketDataRequest) {
+ return marketDataRepository.getAll(marketDataRequest.getStock());
+ }
+
+ @MessageMapping("collectMarketData")
+ public Mono collectMarketData(MarketData marketData) {
+ marketDataRepository.add(marketData);
+ return Mono.empty();
+ }
+
+ @MessageExceptionHandler
+ public Mono handleException(Exception e) {
+ return Mono.just(MarketData.fromException(e));
+ }
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/MarketDataRepository.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/MarketDataRepository.java
new file mode 100644
index 0000000000..4f30c36c2f
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/MarketDataRepository.java
@@ -0,0 +1,37 @@
+package com.baeldung.spring.rsocket.server;
+
+import com.baeldung.spring.rsocket.model.MarketData;
+import java.time.Duration;
+import java.util.Random;
+import java.util.stream.Stream;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+@Slf4j
+@Component
+public class MarketDataRepository {
+
+ private static final int BOUND = 100;
+
+ private Random random = new Random();
+
+ public Flux getAll(String stock) {
+ return Flux.fromStream(Stream.generate(() -> getMarketDataResponse(stock)))
+ .log()
+ .delayElements(Duration.ofSeconds(1));
+ }
+
+ public Mono getOne(String stock) {
+ return Mono.just(getMarketDataResponse(stock));
+ }
+
+ public void add(MarketData marketData) {
+ log.info("New market data: {}", marketData);
+ }
+
+ private MarketData getMarketDataResponse(String stock) {
+ return new MarketData(stock, random.nextInt(BOUND));
+ }
+}
diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/ServerApplication.java b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/ServerApplication.java
new file mode 100644
index 0000000000..4213e315dd
--- /dev/null
+++ b/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket/server/ServerApplication.java
@@ -0,0 +1,16 @@
+package com.baeldung.spring.rsocket.server;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+
+@SpringBootApplication
+public class ServerApplication {
+
+ public static void main(String[] args) {
+ new SpringApplicationBuilder()
+ .main(ServerApplication.class)
+ .sources(ServerApplication.class)
+ .profiles("server")
+ .run(args);
+ }
+}
diff --git a/spring-5-webflux/src/main/resources/application-client.properties b/spring-5-webflux/src/main/resources/application-client.properties
new file mode 100644
index 0000000000..4c00e40deb
--- /dev/null
+++ b/spring-5-webflux/src/main/resources/application-client.properties
@@ -0,0 +1 @@
+server.port=8080
diff --git a/spring-5-webflux/src/main/resources/application-server.properties b/spring-5-webflux/src/main/resources/application-server.properties
new file mode 100644
index 0000000000..1e343b5bf5
--- /dev/null
+++ b/spring-5-webflux/src/main/resources/application-server.properties
@@ -0,0 +1,2 @@
+spring.rsocket.server.port=7000
+server.port=8081
diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/rsocket/client/MarketDataRestControllerIntegrationTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/rsocket/client/MarketDataRestControllerIntegrationTest.java
new file mode 100644
index 0000000000..ff00d5ec24
--- /dev/null
+++ b/spring-5-webflux/src/test/java/com/baeldung/spring/rsocket/client/MarketDataRestControllerIntegrationTest.java
@@ -0,0 +1,92 @@
+package com.baeldung.spring.rsocket.client;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
+
+import com.baeldung.spring.rsocket.model.MarketData;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.messaging.rsocket.RSocketRequester;
+import org.springframework.messaging.rsocket.RSocketRequester.RequestSpec;
+import org.springframework.messaging.rsocket.RSocketRequester.ResponseSpec;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.reactive.server.FluxExchangeResult;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+@RunWith(SpringRunner.class)
+@WebFluxTest(value = MarketDataRestController.class)
+public class MarketDataRestControllerIntegrationTest {
+
+ @Autowired
+ private WebTestClient testClient;
+
+ @MockBean
+ private RSocketRequester rSocketRequester;
+
+ @Mock
+ private RequestSpec requestSpec;
+
+ @Mock
+ private ResponseSpec responseSpec;
+
+ @Test
+ public void whenInitiatesRequest_ThenGetsResponse() throws Exception {
+ when(rSocketRequester.route("currentMarketData")).thenReturn(requestSpec);
+ when(requestSpec.data(any())).thenReturn(responseSpec);
+ MarketData marketData = new MarketData("X", 1);
+ when(responseSpec.retrieveMono(MarketData.class)).thenReturn(Mono.just(marketData));
+
+ testClient.get()
+ .uri("/current/{stock}", "X")
+ .exchange()
+ .expectStatus()
+ .isOk()
+ .expectBody(MarketData.class)
+ .isEqualTo(marketData);
+ }
+
+ @Test
+ public void whenInitiatesFireAndForget_ThenGetsNoResponse() throws Exception {
+ when(rSocketRequester.route("collectMarketData")).thenReturn(requestSpec);
+ when(requestSpec.data(any())).thenReturn(responseSpec);
+ when(responseSpec.send()).thenReturn(Mono.empty());
+
+ testClient.get()
+ .uri("/collect")
+ .exchange()
+ .expectStatus()
+ .isOk()
+ .expectBody(Void.class);
+ }
+
+ @Test
+ public void whenInitiatesRequest_ThenGetsStream() throws Exception {
+ when(rSocketRequester.route("feedMarketData")).thenReturn(requestSpec);
+ when(requestSpec.data(any())).thenReturn(responseSpec);
+ MarketData firstMarketData = new MarketData("X", 1);
+ MarketData secondMarketData = new MarketData("X", 2);
+ when(responseSpec.retrieveFlux(MarketData.class)).thenReturn(Flux.just(firstMarketData, secondMarketData));
+
+ FluxExchangeResult result = testClient.get()
+ .uri("/feed/{stock}", "X")
+ .accept(TEXT_EVENT_STREAM)
+ .exchange()
+ .expectStatus()
+ .isOk()
+ .returnResult(MarketData.class);
+ Flux marketDataFlux = result.getResponseBody();
+ StepVerifier.create(marketDataFlux)
+ .expectNext(firstMarketData)
+ .expectNext(secondMarketData)
+ .thenCancel()
+ .verify();
+ }
+}
\ No newline at end of file
diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/rsocket/server/MarketDataRSocketControllerLiveTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/rsocket/server/MarketDataRSocketControllerLiveTest.java
new file mode 100644
index 0000000000..dcf3b82730
--- /dev/null
+++ b/spring-5-webflux/src/test/java/com/baeldung/spring/rsocket/server/MarketDataRSocketControllerLiveTest.java
@@ -0,0 +1,98 @@
+package com.baeldung.spring.rsocket.server;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+
+import com.baeldung.spring.rsocket.model.MarketData;
+import com.baeldung.spring.rsocket.model.MarketDataRequest;
+import io.rsocket.RSocket;
+import io.rsocket.RSocketFactory;
+import io.rsocket.frame.decoder.PayloadDecoder;
+import io.rsocket.transport.netty.client.TcpClientTransport;
+import java.time.Duration;
+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.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.mock.mockito.SpyBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.messaging.rsocket.RSocketRequester;
+import org.springframework.messaging.rsocket.RSocketStrategies;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.util.MimeTypeUtils;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@TestPropertySource(properties = {"spring.rsocket.server.port=7000"})
+public class MarketDataRSocketControllerLiveTest {
+
+ @Autowired
+ private RSocketRequester rSocketRequester;
+
+ @SpyBean
+ private MarketDataRSocketController rSocketController;
+
+ @Test
+ public void whenGetsFireAndForget_ThenReturnsNoResponse() throws InterruptedException {
+ final MarketData marketData = new MarketData("X", 1);
+ rSocketRequester.route("collectMarketData")
+ .data(marketData)
+ .send()
+ .block(Duration.ofSeconds(10));
+
+ sleepForProcessing();
+ verify(rSocketController).collectMarketData(any());
+ }
+
+ @Test
+ public void whenGetsRequest_ThenReturnsResponse() throws InterruptedException {
+ final MarketDataRequest marketDataRequest = new MarketDataRequest("X");
+ rSocketRequester.route("currentMarketData")
+ .data(marketDataRequest)
+ .send()
+ .block(Duration.ofSeconds(10));
+
+ sleepForProcessing();
+ verify(rSocketController).currentMarketData(any());
+ }
+
+ @Test
+ public void whenGetsRequest_ThenReturnsStream() throws InterruptedException {
+ final MarketDataRequest marketDataRequest = new MarketDataRequest("X");
+ rSocketRequester.route("feedMarketData")
+ .data(marketDataRequest)
+ .send()
+ .block(Duration.ofSeconds(10));
+
+ sleepForProcessing();
+ verify(rSocketController).feedMarketData(any());
+ }
+
+ private void sleepForProcessing() throws InterruptedException {
+ Thread.sleep(1000);
+ }
+
+ @TestConfiguration
+ public static class ClientConfiguration {
+
+ @Bean
+ @Lazy
+ public RSocket rSocket() {
+ return RSocketFactory.connect()
+ .mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE)
+ .frameDecoder(PayloadDecoder.ZERO_COPY)
+ .transport(TcpClientTransport.create(7000))
+ .start()
+ .block();
+ }
+
+ @Bean
+ @Lazy
+ RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
+ return RSocketRequester.wrap(rSocket(), MimeTypeUtils.APPLICATION_JSON, rSocketStrategies);
+ }
+ }
+}
\ No newline at end of file
diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java
index 8919daa9fb..353cb24d0a 100644
--- a/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java
+++ b/spring-5-webflux/src/test/java/com/baeldung/spring/webclientrequests/WebClientRequestsUnitTest.java
@@ -1,5 +1,10 @@
package com.baeldung.spring.webclientrequests;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.time.Duration;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -17,8 +22,6 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.DefaultUriBuilderFactory;
import reactor.core.publisher.Mono;
-import static org.mockito.Mockito.*;
-
@RunWith(SpringRunner.class)
@WebFluxTest
public class WebClientRequestsUnitTest {
@@ -50,7 +53,8 @@ public class WebClientRequestsUnitTest {
public void whenCallSimpleURI_thenURIMatched() {
this.webClient.get()
.uri("/products")
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products");
}
@@ -60,7 +64,8 @@ public class WebClientRequestsUnitTest {
.uri(uriBuilder -> uriBuilder
.path("/products/{id}")
.build(2))
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/2");
}
@@ -70,7 +75,8 @@ public class WebClientRequestsUnitTest {
.uri(uriBuilder -> uriBuilder
.path("/products/{id}/attributes/{attributeId}")
.build(2, 13))
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/2/attributes/13");
}
@@ -83,7 +89,8 @@ public class WebClientRequestsUnitTest {
.queryParam("color", "black")
.queryParam("deliveryDate", "13/04/2019")
.build())
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/?name=AndroidPhone&color=black&deliveryDate=13/04/2019");
}
@@ -96,7 +103,8 @@ public class WebClientRequestsUnitTest {
.queryParam("color", "{authorId}")
.queryParam("deliveryDate", "{date}")
.build("AndroidPhone", "black", "13/04/2019"))
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/?name=AndroidPhone&color=black&deliveryDate=13%2F04%2F2019");
}
@@ -107,7 +115,8 @@ public class WebClientRequestsUnitTest {
.path("/products/")
.queryParam("tag[]", "Snapdragon", "NFC")
.build())
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/?tag%5B%5D=Snapdragon&tag%5B%5D=NFC");
}
@@ -119,7 +128,8 @@ public class WebClientRequestsUnitTest {
.path("/products/")
.queryParam("category", "Phones", "Tablets")
.build())
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/?category=Phones&category=Tablets");
}
@@ -130,7 +140,8 @@ public class WebClientRequestsUnitTest {
.path("/products/")
.queryParam("category", String.join(",", "Phones", "Tablets"))
.build())
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/?category=Phones,Tablets");
}
@@ -151,7 +162,8 @@ public class WebClientRequestsUnitTest {
.queryParam("color", "black")
.queryParam("deliveryDate", "13/04/2019")
.build())
- .retrieve();
+ .exchange()
+ .block(Duration.ofSeconds(1));
verifyCalledUrl("/products/?name=AndroidPhone&color=black&deliveryDate=13/04/2019");
}
diff --git a/spring-all/README.md b/spring-all/README.md
index b0805e5477..b5e91d8d60 100644
--- a/spring-all/README.md
+++ b/spring-all/README.md
@@ -33,5 +33,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Spring @Primary Annotation](http://www.baeldung.com/spring-primary)
- [Spring Events](https://www.baeldung.com/spring-events)
- [Spring Null-Safety Annotations](https://www.baeldung.com/spring-null-safety-annotations)
-- [Spring JDBC](https://www.baeldung.com/spring-jdbc-jdbctemplate)
- [Using @Autowired in Abstract Classes](https://www.baeldung.com/spring-autowired-abstract-class)
diff --git a/spring-cloud/spring-cloud-contract/pom.xml b/spring-cloud/spring-cloud-contract/pom.xml
index 4d4e8ad2c3..ea71891648 100644
--- a/spring-cloud/spring-cloud-contract/pom.xml
+++ b/spring-cloud/spring-cloud-contract/pom.xml
@@ -19,4 +19,45 @@
spring-cloud-contract-consumer
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring-boot.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-data-rest
+ ${spring-boot.version}
+
+
+
+ org.springframework.cloud
+ spring-cloud-contract-wiremock
+ ${spring-cloud.version}
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-contract-stub-runner
+ ${spring-cloud.version}
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-starter-contract-verifier
+ ${spring-cloud.version}
+ test
+
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ 2.1.1.RELEASE
+ 2.1.4.RELEASE
+
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml
index afd045189c..3b711c58d9 100644
--- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml
+++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml
@@ -20,37 +20,27 @@
org.springframework.cloud
spring-cloud-contract-wiremock
- ${spring-cloud.version}
test
org.springframework.cloud
spring-cloud-contract-stub-runner
- ${spring-cloud.version}
test
org.springframework.boot
spring-boot-starter-web
- ${spring-boot.version}
org.springframework.boot
spring-boot-starter-data-rest
- ${spring-boot.version}
com.baeldung.spring.cloud
spring-cloud-contract-producer
- 1.0.0-SNAPSHOT
+ ${project.parent.version}
test
-
- UTF-8
- UTF-8
- 1.2.2.RELEASE
- 1.5.9.RELEASE
-
diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/src/test/java/com/baeldung/spring/cloud/springcloudcontractconsumer/controller/BasicMathControllerIntegrationTest.java b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/src/test/java/com/baeldung/spring/cloud/springcloudcontractconsumer/controller/BasicMathControllerIntegrationTest.java
index 5cf5c6d3b8..e21223e6ea 100644
--- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/src/test/java/com/baeldung/spring/cloud/springcloudcontractconsumer/controller/BasicMathControllerIntegrationTest.java
+++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/src/test/java/com/baeldung/spring/cloud/springcloudcontractconsumer/controller/BasicMathControllerIntegrationTest.java
@@ -7,6 +7,7 @@ import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
+import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
@@ -19,7 +20,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
@AutoConfigureJsonTesters
-@AutoConfigureStubRunner(workOffline = true,
+@AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.LOCAL,
ids = "com.baeldung.spring.cloud:spring-cloud-contract-producer:+:stubs:8090")
public class BasicMathControllerIntegrationTest {
diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml
index 07429687c7..dffbd29206 100644
--- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml
+++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-producer/pom.xml
@@ -25,12 +25,10 @@
org.springframework.boot
spring-boot-starter-web
- ${spring-boot.version}
org.springframework.boot
spring-boot-starter-data-rest
- ${spring-boot.version}
@@ -38,7 +36,7 @@
org.springframework.cloud
spring-cloud-contract-maven-plugin
- 1.2.2.RELEASE
+ 2.1.1.RELEASE
true
com.baeldung.spring.cloud.springcloudcontractproducer.BaseTestClass
@@ -47,25 +45,4 @@
-
-
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- ${spring-cloud.version}
- pom
- import
-
-
-
-
-
- UTF-8
- UTF-8
- Edgware.SR1
- 1.5.9.RELEASE
-
-
diff --git a/spring-security-rest-custom/pom.xml b/spring-security-rest-custom/pom.xml
index 8fdcb509ee..38cbfddab8 100644
--- a/spring-security-rest-custom/pom.xml
+++ b/spring-security-rest-custom/pom.xml
@@ -8,10 +8,10 @@
war
- parent-boot-1
+ parent-boot-2
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-1
+ ../parent-boot-2
diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java b/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java
index 0c2042f711..d7b2da6fe7 100644
--- a/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java
+++ b/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java
@@ -9,14 +9,14 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
@ComponentScan("org.baeldung.web")
// @ImportResource({ "classpath:prop.xml" })
// @PropertySource("classpath:foo.properties")
-public class WebConfig extends WebMvcConfigurerAdapter {
+public class WebConfig implements WebMvcConfigurer {
public WebConfig() {
super();
@@ -26,7 +26,6 @@ public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(final List> converters) {
- super.configureMessageConverters(converters);
converters.add(new MappingJackson2HttpMessageConverter());
}
diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml
index 84e0577cfe..b3074635a7 100644
--- a/testing-modules/junit-5/pom.xml
+++ b/testing-modules/junit-5/pom.xml
@@ -139,7 +139,7 @@
5.4.2
2.8.2
2.0.0-RC.1
- 2.21.0
+ 2.22.0
1.6.0
5.0.1.RELEASE