<div dir="ltr" style="text-align: justify;">
<div style="font-family: calibri, sans-serif; text-align: justify;">
<div style="font-size: 13pt;">
<p>Hello friends!!! Here we are going to discuss Spring Boot with NoSQL, how Spring Boot provide the support for NoSQL technologies and how to use into Spring Boot Application. NoSQL is a non-relational database management systems, different from traditional relational database management systems in some significant ways.</p>
<p>NoSQL is nothing but it is database without support of SQL queries unlike traditional databases MySQL, DB2, Oracle etc. Spring Data provides additional projects that help you access a variety of NoSQL technologies including MongoDB, Neo4J, Elasticsearch, Solr, Redis, Gemfire, Couchbase and Cassandra. Spring Boot provides auto-configuration for Redis, MongoDB, Neo4j, Elasticsearch, Solr and Cassandra.<br />
<b></b></p>
<h2>Spring Boot with NoSQL</h2>
<h2><b>1. MongoDB </b></h2>
<p>MongoDB is an open-source NoSQL document database that uses a JSON-like schema instead of traditional table-based relational data. Spring Boot offers several conveniences for working with MongoDB, including the spring-boot-starter-data-mongodb ‘Starter’. Spring Data includes repository support for MongoDB.</p>
<p>Spring Boot offers auto-configuration for Embedded Mongo. To use it in your Spring Boot application add a dependency on de.flapdoodle.embed:de.flapdoodle.embed.mongo. The port that Mongo will listen on can be configured using the spring.data.mongodb.port property. To use a randomly allocated free port use a value of zero. The MongoClient created by MongoAutoConfiguration will be automatically configured to use the randomly allocated port.</p>
<pre class="highlight">spring.data.mongodb.host=mongoserver 
spring.data.mongodb.port=27017 
</pre>
<h3><b>1.1 Connecting to a MongoDB database</b></h3>
<p>Spring Data Mongo provides a MongoTemplate class that is very similar in its design to Spring’s JdbcTemplate. As with JdbcTemplate Spring Boot auto-configures a bean for you to simply inject:</p>
<pre class="highlight">@Component 
public class DataBean { 
 @Autowired 
 MongoTemplate mongoTemplate; 
// other tasks... 
 
} 
</pre>
<p><b><a href="https://dineshonjava.com/spring-boot-and-mongodb-in-rest-application/">For MongoDB Full Example Click Here<br />
</a></b><b></b></p>
<h2><b>2. Neo4j</b></h2>
<p>Neo4j is an open-source NoSQL graph database that uses a rich data model of nodes related by first class relationships which is better suited for connected big data than traditional rdbms approaches. Spring Boot offers several conveniences for working with Neo4j, including the spring-boot-starter-data-neo4j ‘Starter’.</p>
<p>You can configure the user and credentials to use via the spring.data.neo4j.* properties:</p>
<pre class="highlight">spring.data.neo4j.uri=http://localhost:7474 
spring.data.neo4j.username=neo4j 
spring.data.neo4j.password=secret 
</pre>
<h3><b>2.1 Connecting to a Neo4j database</b></h3>
<pre class="highlight">@Component 
public class DataBean{ 
 @Autowired 
 Neo4jTemplate neo4jTemplate; 
 
 //Other tasks 
} 
</pre>
<p>By default the instance will attempt to connect to a Neo4j server using <b>localhost:7474</b></p>
<h3><b>2.2 Using the embedded mode</b></h3>
<p>If you add org.neo4j:neo4j-ogm-embedded-driver to the dependencies of your application, Spring Boot will automatically configure an in-process embedded instance of Neo4j that will not persist any data when your application shuts down. You can explicitly disable that mode using spring.data.neo4j.embedded.enabled=false.</p>
<pre class="highlight">spring.data.neo4j.uri=file://opt/db/graph.db 
</pre>
<h3><b>2.3 Spring Data Neo4j repositories</b></h3>
<p>Spring Data includes repository support for Neo4j. You can customize entity scanning locations using the @NodeEntityScan annotation.</p>
<pre class="highlight">@EnableNeo4jRepositories(basePackages = "com.dineshonjava.myapp.repository") 
@EnableTransactionManagement 
</pre>
<pre class="highlight">package com.dineshonjava.myapp.domain; 
 
import org.springframework.data.domain.*; 
import org.springframework.data.repository.*; 
 
public interface UserRepository extends GraphRepository<;User>; { 
 
 Page<;User>; findAll(Pageable pageable); 
 
 User findByNameAndEamil(String name, String email); 
 
} 
</pre>
<h2><b>3. Redis</b></h2>
<p>Redis is a cache, message broker and richly-featured key-value store. Spring Boot offers basic auto-configuration for the Jedis client library and abstractions on top of it provided by Spring Data Redis. There is a spring-boot-starter-data-redis ‘Starter’ for collecting the dependencies in a convenient way.</p>
<p>You can inject an auto-configured RedisConnectionFactory, StringRedisTemplate or vanilla RedisTemplate instance as you would any other Spring Bean. By default the instance will attempt to connect to a Redis server using<b> localhost:6379.</b></p>
<pre class="highlight">@Component 
public class DataBean { 
 @Autowired 
 StringRedisTemplate template; 
 
 // other tasks... 
 
} 
</pre>
<h2><b>4. Gemfire</b></h2>
<p>Spring Data Gemfire provides convenient Spring-friendly tools for accessing the Pivotal Gemfire data management platform. There is a spring-boot-starter-data-gemfire ‘Starter’ for collecting the dependencies in a convenient way. There is currently no auto-configuration support for Gemfire, but you can enable Spring Data Repositories with a single annotation (@EnableGemfireRepositories).</p>
<h2><b>5. Solr<br />
</b></h2>
<p>Apache Solr is a search engine. Spring Boot offers basic auto-configuration for the Solr 5 client library and abstractions on top of it provided by Spring Data Solr. There is a spring-boot-starter-data-solr ‘Starter’ for collecting the dependencies in a convenient way.</p>
<p>You can inject an auto-configured SolrClient instance as you would any other Spring bean. By default the instance will attempt to connect to a server using <b>localhost:8983/solr:</b></p>
<pre class="highlight">@Component 
public class DataBean { 
 @Autowired 
 SolrClient solr; 
 
 // other tasks... 
 
} 
</pre>
<h3><b>5.1 Spring Data Solr repositories</b></h3>
<p>Spring Data includes repository support for Apache Solr.</p>
<h2><b>6. Elasticsearch</b></h2>
<p>Elasticsearch is an open source, distributed, real-time search and analytics engine. Spring Boot offers basic auto-configuration for the Elasticsearch and abstractions on top of it provided by Spring Data Elasticsearch. There is a spring-boot-starter-data-elasticsearch ‘Starter’ for collecting the dependencies in a convenient way. Spring Boot also supports Jest.</p>
<h3><b>6.1 Connecting to Elasticsearch using Spring Data</b></h3>
<p>You can inject an auto-configured ElasticsearchTemplate or Elasticsearch Client instance as you would any other Spring Bean. By default the instance will embed a local in-memory server (a Node in Elasticsearch terms) and use the current working directory as the home directory for the server.<br />
you can switch to a remote server by setting spring.data.elasticsearch.cluster-nodes to a comma-separated ‘<b>host:port</b>’ list.</p>
<pre class="highlight">spring.data.elasticsearch.cluster-nodes=localhost:9300 
 
@Component 
public class DataBean { 
 @Autowired 
 ElasticsearchTemplate template; 
 
 //other tasks ... 
 
} 
</pre>
<p>Spring Data includes repository support for Elasticsearch.</p>
<h3><b>6.2 Connecting to Elasticsearch using Jest</b></h3>
<pre class="highlight">spring.elasticsearch.jest.uris=http://search.doj.com:9200 
spring.elasticsearch.jest.read-timeout=10000 
spring.elasticsearch.jest.username=user 
spring.elasticsearch.jest.password=secret 
</pre>
<p>If you have Jest on the classpath, you can inject an auto-configured JestClient targeting localhost:9200 by default.</p>
<h2><b>7. Cassandra</b></h2>
<p>Cassandra is an open source, distributed database management system designed to handle large amounts of data across many commodity servers. Spring Boot offers auto-configuration for Cassandra and abstractions on top of it provided by Spring Data Cassandra. There is a spring-boot-starter-data-cassandra ‘Starter’ for collecting the dependencies in a convenient way.</p>
<h3><b>7.1 Connecting to Cassandra</b></h3>
<p>You can inject an auto-configured CassandraTemplate or a Cassandra Session instance as you would with any other Spring Bean. The spring.data.cassandra.* properties can be used to customize the connection.</p>
<pre class="highlight">spring.data.cassandra.keyspace-name=mykeyspace 
spring.data.cassandra.contact-points=cassandrahost1,cassandrahost2 
 
@Component 
public class DataBean { 
 @Autowired 
 CassandraTemplate template; 
 
 //other tasks ... 
 
} 
</pre>
<h2><b>8. Couchbase</b></h2>
<p>Couchbase is an open-source, distributed multi-model NoSQL document-oriented database that is optimized for interactive applications. Spring Boot offers auto-configuration for Couchbase and abstractions on top of it provided by Spring Data Couchbase. There is a spring-boot-starter-data-couchbase ‘Starter’ for collecting the dependencies in a convenient way.</p>
<p>The spring.couchbase.* properties can be used to customize the connection. Generally you will provide the bootstrap hosts, bucket name and password:</p>
<pre class="highlight">spring.couchbase.bootstrap-hosts=mydojhost-1,192.168.11.111 
spring.couchbase.bucket.name=my-bucket 
spring.couchbase.bucket.password=secret 
</pre>
<p>Spring Data includes repository support for Couchbase. ou can inject an auto-configured CouchbaseTemplate instance.</p>
<pre class="highlight">@Component 
public class DataBean { 
 @Autowired 
 CouchbaseTemplate template; 
 // other tasks... 
 
} 
</pre>
<h2><b>Summary</b></h2>
<p>Here we have discussed some detail about NoSQL database with Spring Boot. Spring Boot Provide major support and auto configuration for connect to NoSQl databases.</p>
<p>Happy Spring Boot Learning!!!</p>
<p><b>Reference</b><br />
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/</p>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;">
<p><b>Spring Boot Related Topics</b></p>
<ol style="text-align: left;">
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/">Introduction to Spring Boo</a>t</b></li>
<li><a href="https://dineshonjava.com/essentials-key-components-and-internals-of-spring-boot-framework/"><b>Essentials and Key Components of Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-cli-installation-and-hello-world-example/"><b>Spring Boot CLI Installation and Hello World Example</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-initilizr-web-interface-and-examples/"><b>Spring Boot Initializr Web Interface</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-initilizr-with-ides-via-spring-tool-suite/"><b>Spring Boot Initializr With IDEs</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-initializr-with-spring-boot-cli/"><b>Spring Boot Initializr With Spring Boot CLI</b></a></li>
<li><a href="https://dineshonjava.com/installing-spring-boot/"><b>Installing Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/developing-your-first-spring-boot-application-hello-world/"><b>Developing your first Spring Boot application</b></a></li>
<li><a href="https://dineshonjava.com/customizing-spring-boot-auto-configuration/"><b>External Configurations for Spring Boot Applications</b></a></li>
<li><a href="https://dineshonjava.com/logging-configuration-in-spring-boot/"><b>Logging Configuration in Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-with-spring-mvc-application/"><b>Spring Boot and Spring MVC</b></a></li>
<li><a href="https://dineshonjava.com/working-with-sql-databases-in-spring-boot-application/"><b>Working with SQL Databases and Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/mysql-configuration-with-spring-boot/"><b>MySQL Configurations</b></a></li>
<li><a href="https://dineshonjava.com/spring-data-jpa-using-in-spring-boot-application/"><b>Spring Data JPA using Spring Boot Application</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-with-nosql-technologies/"><b>Spring Boot with NoSQL technologies</b></a></li>
<li><a href="https://dineshonjava.com/spring-cache-tutorial/"><b>Spring Cache Tutorial</b></a></li>
<li><a href="https://dineshonjava.com/spring-security-tutorial-using-spring-boot/"><b>Spring Security Tutorial with Spring Boot</b></a></li>
<li><a href="https://dineshonjava.com/spring-boot-and-mongodb-in-rest-application/"><b>Spring Boot and MongoDB in REST Application</b></a></li>
<li><b><a href="https://dineshonjava.com/spring-boot-actuator-complete-guide/">Complete Guide for Spring Boot Actuator</a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/">Microservices with Spring Boot</a></b></li>
</ol>
</div>
</div>
</div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-cache-tutorial/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/spring-security-tutorial-using-spring-boot/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '128'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…