{"id":4545,"date":"2018-01-31T03:05:19","date_gmt":"2018-01-31T11:05:19","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4545"},"modified":"2023-07-05T12:13:04","modified_gmt":"2023-07-05T19:13:04","slug":"couchbase-spring-boot-spring-data","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/","title":{"rendered":"Couchbase With Spring-Boot and Spring Data"},"content":{"rendered":"<p><span style=\"font-weight: 400\">One of the biggest barriers for anyone who wants to start using new technologies is usually the learning curve. Often while starting a new project, we end up choosing to use what we already know to avoid any friction right at the beginning.<\/span><\/p>\n<p><span style=\"font-weight: 400\">I have spent most of my career working as a Java developer, and in the last few years I fell in love with the <a href=\"https:\/\/docs.oracle.com\/javaee\/5\/tutorial\/doc\/?wp406143&amp;PersistenceIntro.html#wp78460\">JPA<\/a> + <a href=\"https:\/\/projects.spring.io\/spring-boot\/\">Spring-Boot<\/a> + <a href=\"https:\/\/projectlombok.org\/\">Lombok<\/a> + <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/docs\/current\/reference\/html\/\">Spring Data<\/a> combination, but the one thing that still annoyed me was mapping relationships.<\/span><\/p>\n<p><span style=\"font-weight: 400\">JPA is known for loading unnecessary data from the database, and over time you are forced to revisit some of your entities to change a few relationships from EAGER to LAZY. It can significantly improve your performance as you will avoid a lot of unnecessary JOINS but it does not come for free. You will be required to do a lot of refactoring to load those new lazy objects whenever they are required. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This common pattern always bothered me and I was really happy when I found that Spring Data and Couchbase can connect (<a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/reference\/html\/\">full doc here<\/a>). It is simply the best part of two worlds, I can program like I would in a relational database but still leveraging all the speed of Couchbase and the power of N1QL. Let\u2019s see how to set up a simple project.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Setting-Up Spring Data, Spring Boot, and Couchbase<\/b><\/h3>\n<p>&nbsp;<\/p>\n<h4><b>Prerequisites: <\/b><\/h4>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">I will assume that you already have Couchbase installed, if you don\u2019t, please <\/span><a href=\"https:\/\/www.couchbase.com\/downloads\/\"><span style=\"font-weight: 400\">download it here<\/span><\/a><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">I am also using Lombok, so you might need to install Lombok\u2019s plugin on your IDE: E<\/span><a href=\"https:\/\/projectlombok.org\/setup\/eclipse\"><span style=\"font-weight: 400\">clipse<\/span><\/a><span style=\"font-weight: 400\"> and <\/span><span style=\"font-weight: 400\"><a href=\"https:\/\/plugins.jetbrains.com\/plugin\/6317-lombok-plugin\">IntelliJ IDEA<\/a><\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">First, you can clone my project:<\/span><\/p>\n<pre class=\"lang:default decode:true\">git clone https:\/\/github.com\/deniswsrosa\/couchbase-spring-data-sample.git<\/pre>\n<p><span style=\"font-weight: 400\">or simply go to <\/span><a href=\"https:\/\/start.spring.io\/\"><span style=\"font-weight: 400\">Spring-Boot Initialzr<\/span><\/a><span style=\"font-weight: 400\"> and add Couchbase and Lombok as dependencies:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4546\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/Spring-boot-initialzr-1024x451.png\" alt=\"\" width=\"730\" height=\"321\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-1024x451.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-300x132.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-768x338.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-1536x676.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-2048x901.png 2048w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-20x9.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/Spring-boot-initialzr-1320x581.png 1320w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p style=\"text-align: center\"><b>Note:<\/b><span style=\"font-weight: 400\"> Lombok is not a required dependency, but it helps to significantly reduce your code base.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Now, let\u2019s define your bucket configuration in the <em><strong>application.properties<\/strong><\/em> file:<\/span><\/p>\n<pre class=\"lang:default decode:true\">spring.couchbase.bootstrap-hosts=localhost\r\nspring.couchbase.bucket.name=test\r\nspring.couchbase.bucket.password=couchbase\r\nspring.data.couchbase.auto-index=true<\/pre>\n<p><span style=\"font-weight: 400\">And that&#8217;s it! You are already able to start up your project using:<\/span><\/p>\n<pre class=\"lang:default decode:true \">mvn spring-boot:run<\/pre>\n<p>&nbsp;<\/p>\n<h3><b>Mapping an Entity<\/b><\/h3>\n<p><span style=\"font-weight: 400\">So far, our project does not do anything. Let\u2019s create and map our first entity:<\/span><\/p>\n<pre class=\"lang:java decode:true \">@Document\r\n@Data\r\n@AllArgsConstructor\r\n@NoArgsConstructor\r\n@EqualsAndHashCode\r\npublic class Building {\r\n\r\n    @NotNull\r\n    @Id\r\n    private String id;\r\n\r\n    @NotNull\r\n    @Field\r\n    private String name;\r\n\r\n    @NotNull\r\n    @Field\r\n    private String companyId;\r\n\r\n    @Field\r\n    private List&lt;Area&gt; areas = new ArrayList&lt;&gt;();\r\n\r\n    @Field\r\n    private List&lt;String&gt; phoneNumbers = new ArrayList&lt;&gt;();\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"font-weight: 400\"><b>@Document:<\/b><span style=\"font-weight: 400\"> Couchbase\u2019s annotation which defines an entity, similar to <em><strong>@Entity<\/strong><\/em> in JPA. Couchbase will automatically add a property called <\/span><b><i>_class<\/i><\/b><span style=\"font-weight: 400\"> in the document to use it as the document type.<\/span><\/li>\n<li style=\"font-weight: 400\"><b>@Data: \u00a0<span style=\"font-weight: 400\">Lombok\u2019s annotation, auto-generate getters and setters<\/span><\/b><\/li>\n<li style=\"font-weight: 400\"><strong>@AllArgsConstructor:<\/strong><span style=\"font-weight: 400\"> Lombok\u2019s annotation, auto-generate a constructor using all fields of the class, this constructor <a href=\"https:\/\/github.com\/deniswsrosa\/couchbase-spring-data-sample\/blob\/master\/src\/test\/java\/com\/cb\/springdata\/sample\/BuildingServiceIntegrationTest.java\">is used in our tests<\/a>.<\/span><\/li>\n<li style=\"font-weight: 400\"><strong>@NoArgsConstructor:<\/strong> <span style=\"font-weight: 400\">Lombok\u2019s annotation, auto-generate a constructor with no args (required by Spring Data)<\/span><\/li>\n<li style=\"font-weight: 400\"><strong>@EqualsAndHashCode:<\/strong> <span style=\"font-weight: 400\">Lombok\u2019s annotation, auto-generate equals and hashcode methods, also used in our tests.<\/span><\/li>\n<li style=\"font-weight: 400\"><strong>@NotNull:<\/strong> <span style=\"font-weight: 400\">Yes! You can use javax.validation with Couchbase.<\/span><\/li>\n<li style=\"font-weight: 400\"><strong>@Id:<\/strong><span style=\"font-weight: 400\"> The document&#8217;s key<\/span><\/li>\n<li style=\"font-weight: 400\"><strong>@Field:<\/strong> <span style=\"font-weight: 400\">\u00a0Couchbase\u2019s annotations, similar to <em><strong>@Column<\/strong><\/em><\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Mapping entities in Couchbase is really simple and straightforward, the biggest difference here is the <\/span><b>@Field<\/b><span style=\"font-weight: 400\"> entity which is used in 3 different ways:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><b>Simple property:<\/b><span style=\"font-weight: 400\"> In cases like <\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">, <\/span><i><span style=\"font-weight: 400\">name\u00a0<\/span><\/i><span style=\"font-weight: 400\">and <\/span><i><span style=\"font-weight: 400\">companyId,<\/span><\/i><span style=\"font-weight: 400\"> the <em><strong>@Field<\/strong><\/em> acts pretty much like the <em><strong>@Column<\/strong><\/em> in JPA. \u00a0It will result in a simple property in the document:<\/span><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">{\r\n\u00a0\"id\": \"building::1\",\r\n\u00a0\"name\": \"Couchbase's Building\",\r\n\u00a0\"companyId\": \"company::1\"\r\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><b>Arrays<\/b><span style=\"font-weight: 400\">: In the phoneNumbers\u2019s case it will result in an array inside the document:<\/span><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">{\r\n\u00a0\"phoneNumbers\": [\"phoneNumber1\", \"phoneNumber2\"]\r\n}\r\n<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><b>Entities<\/b><span style=\"font-weight: 400\">: Finally, in the areas\u2019s case, <\/span><b>@Field<\/b><span style=\"font-weight: 400\"> acts like a <\/span><em><b>@ManyToOne<\/b><\/em><span style=\"font-weight: 400\"> relationship, the main difference is that you are not required to map anything in the Area entity:<\/span><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">@EqualsAndHashCode\r\n@AllArgsConstructor\r\n@NoArgsConstructor\r\n@Data\r\npublic class Area {\r\n\r\n    private String id;\r\n\r\n    private String name;\r\n\r\n    private List&lt;Area&gt; areas = new ArrayList&lt;&gt;();\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3><b>Repositories<\/b><\/h3>\n<p><span style=\"font-weight: 400\">Your repositories will look very similar to standard Spring Data repositories but with a few extra annotations:<\/span><\/p>\n<pre class=\"lang:default decode:true \">@N1qlPrimaryIndexed\r\n@ViewIndexed(designDoc = \"building\")\r\npublic interface BuildingRepository extends CouchbasePagingAndSortingRepository&lt;Building, String&gt; {\r\n\r\n    List&lt;Building&gt; findByCompanyId(String companyId);\r\n\r\n    Page&lt;Building&gt; findByCompanyIdAndNameLikeOrderByName(String companyId, String name, Pageable pageable);\r\n\r\n    @Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} and companyId = $1 and $2 within #{#n1ql.bucket}\")\r\n    Building findByCompanyAndAreaId(String companyId, String areaId);\r\n\r\n    @Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY phone IN phoneNumbers SATISFIES phone = $1 END\")\r\n    List&lt;Building&gt; findByPhoneNumber(String telephoneNumber);\r\n\r\n    @Query(\"SELECT COUNT(*) AS count FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} and companyId = $1\")\r\n    Long countBuildings(String companyId);\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"font-weight: 400\"><b>@N1qlPrimaryIndexed<\/b><span style=\"font-weight: 400\">: This\u00a0<\/span><a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/api\/index.html?org\/springframework\/data\/couchbase\/core\/query\/N1qlPrimaryIndexed.html\"><span style=\"font-weight: 400\">annotation<\/span><\/a><span style=\"font-weight: 400\">\u00a0makes sure that the bucket associated with the current repository will have a N1QL primary index<\/span><\/li>\n<li style=\"font-weight: 400\"><b>@ViewIndexed: \u00a0<\/b><span style=\"font-weight: 400\">This\u00a0<\/span><a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/api\/index.html?org\/springframework\/data\/couchbase\/core\/query\/ViewIndexed.html\"><span style=\"font-weight: 400\">annotation<\/span><\/a><span style=\"font-weight: 400\">\u00a0lets you define the name of the design document and View name as well as a custom map and reduce function.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">In the repository above, we are extending <\/span><b><i>CouchbasePagingAndSortingRepository<\/i><\/b><span style=\"font-weight: 400\">, which allows you to paginate your queries by simply adding a <\/span><b><i>Pageable<\/i><\/b><span style=\"font-weight: 400\"> param at the end of your method definition<\/span><\/p>\n<p><span style=\"font-weight: 400\">As it is essentially a repository, you can leverage all <\/span><a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/reference\/html\/#couchbase.repository.querying\"><span style=\"font-weight: 400\">Spring Data keywords<\/span><\/a><span style=\"font-weight: 400\"> like <\/span><b><i>FindBy<\/i><\/b><span style=\"font-weight: 400\">, <\/span><b><i>Between<\/i><\/b><span style=\"font-weight: 400\">, <\/span><b><i>IsGreaterThan<\/i><\/b><span style=\"font-weight: 400\">, <\/span><b><i>Like<\/i><\/b><span style=\"font-weight: 400\">, <\/span><b><i>Exists<\/i><\/b><span style=\"font-weight: 400\">, etc. So, you can start using Couchbase with almost no previous knowledge and still be very productive.<\/span><\/p>\n<p><span style=\"font-weight: 400\">As you might have noticed, you can create full <\/span><a href=\"https:\/\/query-tutorial.couchbase.com\/tutorial\/\"><span style=\"font-weight: 400\">N1QL<\/span><\/a><span style=\"font-weight: 400\"> queries but with a few syntax-sugars:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><b>#(#n1ql.bucket):<\/b><span style=\"font-weight: 400\"> \u00a0Use this syntax avoids hard-coding your bucket name in your query<\/span><\/li>\n<li><b>#{#n1ql.selectEntity}:<span style=\"font-weight: 400\"> syntax-sugar to <\/span><i>SELECT * FROM #(#n1ql.bucket)<\/i>:<span style=\"font-weight: 400\"> \u00a0<\/span><\/b><\/li>\n<li><strong>#{#n1ql.filter}:<\/strong><span style=\"font-weight: 400\"> syntax-sugar to filter the document by type, technically it means <\/span><strong><i>class = \u2018myPackage.MyClassName\u2019<\/i><\/strong><i><span style=\"font-weight: 400\"> (<\/span><\/i><span style=\"font-weight: 400\"><em><strong>_class<\/strong><\/em> is the attribute automatically added in the document to define its type when you are working with Couchbase on Spring Data )<\/span><\/li>\n<li><b>#{<\/b><b>#n1ql.fields}\u00a0<\/b>will be replaced by the list of fields (eg. for a SELECT clause) necessary to reconstruct the entity.<\/li>\n<li><b>#{<\/b><b>#n1ql.delete}\u00a0<\/b><span style=\"font-weight: 400\">will be replaced by the\u00a0delete from\u00a0statement.<\/span><\/li>\n<li><b>#{<\/b><b>#n1ql.returning}\u00a0<\/b><span style=\"font-weight: 400\">will be replaced by the returning clause needed for reconstructing the entity.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">To demonstrate some of the cool capabilities of N1QL, let\u2019s go a little deeper in two methods of our repository: <\/span><b><i>findByPhoneNumber<\/i><\/b><span style=\"font-weight: 400\"> and <\/span><b><i>findByCompanyAndAreaId:<\/i><\/b><\/p>\n<p>&nbsp;<\/p>\n<h4><b>findByPhoneNumber<\/b><\/h4>\n<pre class=\"lang:default decode:true\">@Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY phone IN phoneNumbers SATISFIES phone = $1 END\")\r\nList&lt;Building&gt; findByPhoneNumber(String telephoneNumber);<\/pre>\n<p><span style=\"font-weight: 400\">In the case above we are simply searching for buildings by telephone numbers. In a relational world, you would normally need 2 tables to accomplish nearly the same thing. With Couchbase we can store everything in a single document, which makes loading a \u201cbuilding\u201d much faster than what you would get using any RDBMS.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Additionally, you can speed up your query performance even more by <\/span><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/indexing-arrays.html\"><span style=\"font-weight: 400\">adding an index on the phoneNumbers attribute<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h4><b>findByCompanyAndAreaId<\/b><\/h4>\n<pre class=\"lang:default decode:true \">@Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} and companyId = $1 and $2 within #{#n1ql.bucket}\")\r\nBuilding findByCompanyAndAreaId(String companyId, String areaId);<\/pre>\n<p><span style=\"font-weight: 400\">In the query above we are basically trying to find the root node (Building) giving a random child node (Area). Our data is structured as a tree because an Area could also have a list of other areas:<\/span><\/p>\n<pre class=\"lang:default decode:true \">@EqualsAndHashCode\r\n@AllArgsConstructor\r\n@NoArgsConstructor\r\n@Data\r\npublic class Area {\r\n\r\n    private String id;\r\n\r\n    private String name;\r\n\r\n    private List&lt;Area&gt; areas = new ArrayList&lt;&gt;();\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>This type of querying is one of the most expensive and complex operations when you are working with a relational database, in most of the cases you either find the root node <em>by hand<\/em> or by using some big fat query with <em><b>UNIONs<\/b><\/em> and <b><i>CONNECTED BYs<\/i><\/b>.<\/p>\n<p><span style=\"font-weight: 400\">Here you can solve this problem by using a magical keyword called <\/span><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/collectionops.html\"><span style=\"font-weight: 400\">WITHIN<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Services<\/b><\/h3>\n<p><span style=\"font-weight: 400\">By default, you will inject and use your repositories in your Services like you normally would, but you can additionally access Couchbase\u2019s specific repositories capabilities using the method <\/span><b>getCouchbaseOperations()<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4547\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/couchbase_operations-1024x478.png\" alt=\"\" width=\"699\" height=\"326\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations-1024x478.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations-300x140.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations-768x359.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations-1536x718.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations-20x9.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations-1320x617.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/01\/couchbase_operations.png 1796w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Everything in Action<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p>Using\u00a0 services are to exactly what you would expect:<\/p>\n<pre class=\"lang:default decode:true \">buildingService.findById(\"building::1\")\r\n<\/pre>\n<pre class=\"lang:default decode:true\">Building bulding = new Building(\"bulding::1\", \"Couchbase Building\",\r\n                \"company::1\", new ArrayList&lt;&gt;(), new ArrayList&lt;&gt;());\r\n\r\nbuildingService.save(building);<\/pre>\n<pre class=\"lang:default decode:true \">buildingService.findByCompanyIdAndNameLike(\"company::1\", \"Cou%\", 0);<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Check out the integration test class <a href=\"https:\/\/github.com\/deniswsrosa\/couchbase-spring-data-sample\/blob\/master\/src\/test\/java\/com\/cb\/springdata\/sample\/BuildingServiceIntegrationTest.java\">BuildingServiceIntegrationTest<\/a> to see everything in action.<\/span><\/p>\n<p><span style=\"font-weight: 400\">If you have any questions, tweet me at <a href=\"https:\/\/twitter.com\/deniswsrosa\">@deniswsrosa<\/a> or ask a question on our <\/span><a href=\"https:\/\/www.couchbase.com\/forums\/\"><span style=\"font-weight: 400\">forum<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the biggest barriers for anyone who wants to start using new technologies is usually the learning curve. Often while starting a new project, we end up choosing to use what we already know to avoid any friction right [&hellip;]<\/p>\n","protected":false},"author":8754,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,1818],"tags":[],"ppma_author":[9059],"class_list":["post-4545","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring-Boot and Spring Data: Setting Up with Couchbase<\/title>\n<meta name=\"description\" content=\"Need to learn how to set up Spring Data, Spring Boot, and Couchbase? This blog post will show your prerequisites, repositories, and everything in action.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Couchbase With Spring-Boot and Spring Data\" \/>\n<meta property=\"og:description\" content=\"Need to learn how to set up Spring Data, Spring Boot, and Couchbase? This blog post will show your prerequisites, repositories, and everything in action.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-31T11:05:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-05T19:13:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/Spring-boot-initialzr-1024x451.png\" \/>\n<meta name=\"author\" content=\"Denis Rosa, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@deniswsrosa\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Rosa, Developer Advocate, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\"},\"author\":{\"name\":\"Denis Rosa, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257\"},\"headline\":\"Couchbase With Spring-Boot and Spring Data\",\"datePublished\":\"2018-01-31T11:05:19+00:00\",\"dateModified\":\"2023-07-05T19:13:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\"},\"wordCount\":1098,\"commentCount\":11,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"Best Practices and Tutorials\",\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\",\"name\":\"Spring-Boot and Spring Data: Setting Up with Couchbase\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2018-01-31T11:05:19+00:00\",\"dateModified\":\"2023-07-05T19:13:04+00:00\",\"description\":\"Need to learn how to set up Spring Data, Spring Boot, and Couchbase? This blog post will show your prerequisites, repositories, and everything in action.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Couchbase With Spring-Boot and Spring Data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257\",\"name\":\"Denis Rosa, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/be0716f6199cfb09417c92cf7a8fa8d6\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g\",\"caption\":\"Denis Rosa, Developer Advocate, Couchbase\"},\"description\":\"Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app.\",\"sameAs\":[\"https:\/\/x.com\/deniswsrosa\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/denis-rosa\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Spring-Boot and Spring Data: Setting Up with Couchbase","description":"Need to learn how to set up Spring Data, Spring Boot, and Couchbase? This blog post will show your prerequisites, repositories, and everything in action.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/","og_locale":"en_US","og_type":"article","og_title":"Couchbase With Spring-Boot and Spring Data","og_description":"Need to learn how to set up Spring Data, Spring Boot, and Couchbase? This blog post will show your prerequisites, repositories, and everything in action.","og_url":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/","og_site_name":"The Couchbase Blog","article_published_time":"2018-01-31T11:05:19+00:00","article_modified_time":"2023-07-05T19:13:04+00:00","og_image":[{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/01\/Spring-boot-initialzr-1024x451.png","type":"","width":"","height":""}],"author":"Denis Rosa, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@deniswsrosa","twitter_misc":{"Written by":"Denis Rosa, Developer Advocate, Couchbase","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/"},"author":{"name":"Denis Rosa, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257"},"headline":"Couchbase With Spring-Boot and Spring Data","datePublished":"2018-01-31T11:05:19+00:00","dateModified":"2023-07-05T19:13:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/"},"wordCount":1098,"commentCount":11,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["Best Practices and Tutorials","Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/","url":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/","name":"Spring-Boot and Spring Data: Setting Up with Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2018-01-31T11:05:19+00:00","dateModified":"2023-07-05T19:13:04+00:00","description":"Need to learn how to set up Spring Data, Spring Boot, and Couchbase? This blog post will show your prerequisites, repositories, and everything in action.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Couchbase With Spring-Boot and Spring Data"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257","name":"Denis Rosa, Developer Advocate, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/be0716f6199cfb09417c92cf7a8fa8d6","url":"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g","caption":"Denis Rosa, Developer Advocate, Couchbase"},"description":"Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app.","sameAs":["https:\/\/x.com\/deniswsrosa"],"url":"https:\/\/www.couchbase.com\/blog\/author\/denis-rosa\/"}]}},"authors":[{"term_id":9059,"user_id":8754,"is_guest":0,"slug":"denis-rosa","display_name":"Denis Rosa, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f8d1f5c13115122cab89d0f229b904480bfe20d3dfbb093fe9734cda5235d419?s=96&d=mm&r=g","author_category":"","last_name":"Rosa, Developer Advocate, Couchbase","first_name":"Denis","job_title":"","user_url":"","description":"Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/8754"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4545"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4545\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4545"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}