{"id":5267,"date":"2018-06-11T03:01:59","date_gmt":"2018-06-11T10:01:59","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=5267"},"modified":"2023-07-20T14:48:34","modified_gmt":"2023-07-20T21:48:34","slug":"kotlin-spring-boot-spring-data","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/","title":{"rendered":"Couchbase with Kotlin, Spring Boot and Spring Data"},"content":{"rendered":"<p>Last year I started learning Kotlin and I was surprised at how easy it was to convert a Java application. IntelliJ and a few other IDEs offer nice tools for automatic conversion, and with a few adjustments you can end up with a much more concise and less error-prone code.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-5268\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-1024x252.png\" alt=\"\" width=\"721\" height=\"177\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-1024x252.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-300x74.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-768x189.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-20x5.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM.png 1120w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/p>\n<p>So, I decided to create a sample application to show my new favorite combination: Kotlin, <a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-spring-boot-spring-data\/\">Spring Boot, Spring Data, and Couchbase<\/a>:<\/p>\n<h2><strong>Creating a User Profile Service <\/strong><\/h2>\n<p>You can clone the whole project here:<\/p>\n<p><a href=\"https:\/\/github.com\/couchbaselabs\/try-cb-kotlin\">https:\/\/github.com\/couchbaselabs\/try-cb-kotlin<\/a><\/p>\n<p>Let\u2019s start by creating our main class:<\/p>\n<pre class=\"lang:default decode:true\">@SpringBootApplication\r\nopen class KotlinDemoApplication\r\n\r\nfun main(args: Array&lt;String&gt;) {\r\n    SpringApplication.run(KotlinDemoApplication::class.java, *args)\r\n}<\/pre>\n<p><strong>\u00a0Note:<\/strong> You class must be <strong>open<\/strong> otherwise you will end up with the following error:<\/p>\n<pre class=\"lang:default decode:true \">org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'KotlinDemoApplication' may not be final. Remove the final modifier to continue.\r\nOffending resource: com.couchbase.KotlinDemoApplication\r\n\tat org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]\r\n\tat org.springframework.context.annotation.ConfigurationClass.validate(ConfigurationClass.java:214) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]\r\n<\/pre>\n<p>Here is our User entity, it is very similar to <a href=\"https:\/\/github.com\/couchbaselabs\/kubernetes-starter-kit\/blob\/master\/src\/main\/java\/com\/cb\/springdata\/sample\/entities\/User.java\">the Java one<\/a>:<\/p>\n<pre class=\"lang:default decode:true\">@Document\r\nclass User(): BasicEntity() {\r\n\r\n    constructor(id: String,\r\n                name: String,\r\n                address: Address,\r\n                preferences: List&lt;Preference&gt;,\r\n                securityRoles: List&lt;String&gt;): this(){\r\n\r\n        this.id = id;\r\n        this.name = name;\r\n        this.address = address;\r\n        this.preferences = preferences;\r\n        this.securityRoles = securityRoles;\r\n    }\r\n\r\n    @Id\r\n    var id: String? = null\r\n\r\n    @NotNull\r\n    var name: String? = null\r\n\r\n    @Field\r\n    var address: Address? = null\r\n\r\n    @Field\r\n    var preferences: List&lt;Preference&gt; = emptyList()\r\n\r\n    @Field\r\n    var securityRoles: List&lt;String&gt; = emptyList()\r\n}<\/pre>\n<ul>\n<li><strong>@Document:\u00a0<\/strong>Couchbase\u2019s annotation which defines an entity, similar to\u00a0<strong><em>@Entity<\/em><\/strong>\u00a0in JPA. Couchbase will automatically add a property called\u00a0<strong><em>_class<\/em><\/strong>\u00a0in the document to use it as the document type.<\/li>\n<li><strong>@Id:\u00a0<\/strong>The document\u2019s key<\/li>\n<li><strong>@Field:<\/strong>\u00a0Couchbase\u2019s annotations, similar to JPA\u2019s\u00a0<strong><em>@Column<\/em><\/strong>. It is not mandatory, but we do recommend using it.<\/li>\n<\/ul>\n<p>Mapping attributes in Couchbase are really simple. They will be directly mapped to the correspondent structure in JSON:<\/p>\n<ul>\n<li><strong>Simple Properties:<\/strong> Straightforward mapping to JSON:<\/li>\n<\/ul>\n<pre class=\"lang:js decode:true\">{\r\n \"id\": \"user::1\",\r\n \"name\": \"Denis Rosa\"\r\n}<\/pre>\n<ul>\n<li><strong>Arrays: <\/strong>As you might expect, arrays like <strong>securityRoles<\/strong> will be converted to JSON arrays:<strong>\u00a0<\/strong><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">{\r\n \"securityRoles\": [\"admin\", \"user\"]\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>Nested Entities:<\/strong> Do you hate to map <strong>@ManyToOne<\/strong> relationships? Me too. As we are using a document database, there is no need to write these relationships anymore, nested entities are also directly translated to JSON.<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">{  \r\n   \"id\":\"user::1\",\r\n   \"name\":\"Denis Rosa\",\r\n   \"address\":{  \r\n      \"streetName\":\"A Street Somewhere\",\r\n      \"houseNumber\":\"42\",\r\n      \"postalCode\":\"81234\",\r\n      \"city\":\"Munich\",\r\n      \"country\":\"DE\"\r\n   },\r\n   \"preferences\":[  \r\n      {  \r\n         \"name\":\"lang\",\r\n         \"value\":\"EN\"\r\n      }\r\n   ],\r\n   \"securityRoles\":[  \r\n      \"admin\",\r\n      \"user\"\r\n   ]\r\n}<\/pre>\n<h2><strong>Repositories<\/strong><\/h2>\n<p>Now, let\u2019s take a look at how our repository will look like:<\/p>\n<pre class=\"lang:default decode:true \">@N1qlPrimaryIndexed\r\n@ViewIndexed(designDoc = \"user\")\r\ninterface UserRepository : CouchbasePagingAndSortingRepository&lt;User, String&gt; {\r\n\r\n    fun findByName(name: String): List&lt;User&gt;\r\n\r\n    @Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} and ANY preference IN \" + \" preferences SATISFIES preference.name = $1 END\")\r\n    fun findUsersByPreferenceName(name: String): List&lt;User&gt;\r\n\r\n    @Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} and meta().id = $1 and ARRAY_CONTAINS(securityRoles, $2)\")\r\n    fun hasRole(userId: String, role: String): User\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>@N1qlPrimaryIndexed<\/strong>: This\u00a0<a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/api\/index.html?org\/springframework\/data\/couchbase\/core\/query\/N1qlPrimaryIndexed.html\">annotation\u00a0<\/a>makes sure that the bucket associated with the current repository will have a N1QL primary index<\/li>\n<li><strong>@ViewIndexed: \u00a0<\/strong>This\u00a0<a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/api\/index.html?org\/springframework\/data\/couchbase\/core\/query\/ViewIndexed.html\">annotation\u00a0<\/a>lets you define the name of the design document and View name as well as a custom map and reduce function.<\/li>\n<\/ul>\n<p>As you can see below, you can leverage all\u00a0<a href=\"https:\/\/docs.spring.io\/spring-data\/couchbase\/docs\/current\/reference\/html\/#couchbase.repository.querying\">Spring Data keywords<\/a>\u00a0to query the database, such as\u00a0<strong><em>FindBy<\/em><\/strong>,\u00a0<strong><em>Between<\/em><\/strong>,\u00a0<strong><em>IsGreaterThan<\/em><\/strong>,\u00a0 <strong><em>Like<\/em><\/strong>, <strong><em>Exists<\/em><\/strong>, etc.<\/p>\n<pre class=\"lang:default decode:true\">    fun findByName(name: String): List&lt;User&gt;<\/pre>\n<p>The repository is extending\u00a0<strong><em>CouchbasePagingAndSortingRepository<\/em><\/strong>, which allows you to paginate your queries by simply adding a\u00a0<strong><em>Pageable<\/em><\/strong>\u00a0param at the end of your method definition. If you need to write more powerful queries, you can also use N1QL:<\/p>\n<pre class=\"lang:default decode:true\">    @Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} and ANY preference IN \" + \" preferences SATISFIES preference.name = $1 END\")\r\n    fun findUsersByPreferenceName(name: String): List&lt;User&gt;\r\n\r\n    @Query(\"#{#n1ql.selectEntity} where #{#n1ql.filter} and meta().id = $1 and ARRAY_CONTAINS(securityRoles, $2)\")\r\n    fun hasRole(userId: String, role: String): User<\/pre>\n<p>The queries above have a few syntax-sugars to make it smaller:<\/p>\n<ul>\n<li><strong>#(#n1ql.bucket):\u00a0<\/strong><span style=\"font-style: inherit\">Use this syntax avoids hard-coding the bucket name in your query<\/span><\/li>\n<li><strong>#{#n1ql.selectEntity}:\u00a0<\/strong>syntax-sugar to\u00a0<strong><em>SELECT * FROM #(#n1ql.bucket)<\/em><\/strong><strong>:<\/strong><\/li>\n<li><strong style=\"font-style: inherit\">#{#n1ql.filter}:\u00a0<\/strong><span style=\"font-style: inherit\">syntax-sugar to filter the document by type, technically it means\u00a0<\/span><strong style=\"font-style: inherit\"><em>class = \u2018myPackage.MyClassName\u2019<\/em><\/strong><em><span style=\"font-style: inherit\">\u00a0(<\/span><strong style=\"font-style: inherit\"><span style=\"font-style: inherit\">_class<\/span><\/strong><\/em>\u00a0is the attribute automatically added to the document to define its type when you are working with Couchbase on Spring Data )<\/li>\n<li><strong>#{#n1ql.fields}\u00a0<\/strong>will be replaced by the list of fields (eg. for a SELECT clause) necessary to reconstruct the entity.<\/li>\n<li><strong>#{#n1ql.delete}\u00a0<\/strong><span style=\"font-style: inherit\">will be replaced by the\u00a0delete from\u00a0statement.<\/span><\/li>\n<li><strong>#{#n1ql.returning}\u00a0<\/strong><span style=\"font-style: inherit\">will be replaced by returning clause needed for reconstructing entity.<\/span><\/li>\n<\/ul>\n<h2><strong>Services<\/strong><\/h2>\n<p>Our service is basically forwarding requests to our repository, but if you need to write ad-hoc queries, here is the right place:<\/p>\n<pre class=\"lang:default decode:true \">@Service\r\nclass UserService {\r\n\r\n    @Autowired\r\n    lateinit var userRepository: UserRepository;\r\n\r\n    fun findByName(name: String): List&lt;User&gt; = userRepository.findByName(name)\r\n\r\n    fun findById(userId: String) = userRepository.findOne(userId)\r\n\r\n    fun save(@Valid user: User) = userRepository.save(user)\r\n\r\n    fun findUsersByPreferenceName(name: String): List&lt;User&gt; = userRepository.findUsersByPreferenceName(name)\r\n\r\n    fun hasRole(userId: String, role: String): Boolean {\r\n        return userRepository.hasRole(userId, role) != null\r\n    }\r\n\r\n    \/**\r\n     * Example of ad hoc queries\r\n     *\/\r\n    fun findUserByAddress(streetName: String = \"\", number: String = \"\", postalCode: String = \"\",\r\n                          city: String = \"\", country: String = \"\"): List&lt;User&gt; {\r\n\r\n        var query = \"SELECT meta(b).id as id, b.* FROM \" + getBucketName() + \" b WHERE  b._class = '\" + User::class.java.getName() + \"' \"\r\n\r\n        if (!streetName.isNullOrBlank()) query += \" and b.address.streetName = '$streetName' \"\r\n\r\n        if (!number.isNullOrBlank()) query += \" and b.address.houseNumber = '$number' \"\r\n\r\n        if (!postalCode.isNullOrBlank()) query += \" and b.address.postalCode = '$postalCode' \"\r\n\r\n        if (!city.isNullOrBlank()) query += \" and b.address.city = '$city' \"\r\n\r\n        if (!country.isNullOrBlank()) query += \" and b.address.country = '$country' \"\r\n\r\n        val params = N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS).adhoc(true)\r\n        val paramQuery = N1qlQuery.parameterized(query, JsonObject.create(), params)\r\n        return userRepository.getCouchbaseOperations().findByN1QLProjection(paramQuery, User::class.java)\r\n    }\r\n\r\n    fun getBucketName() = userRepository.getCouchbaseOperations().getCouchbaseBucket().bucketManager().info().name()\r\n}<\/pre>\n<h2><strong>Controllers<\/strong><\/h2>\n<p>Finally, let\u2019s also add a controller to test our services via rest:<\/p>\n<pre class=\"lang:default decode:true\">@RestController\r\n@RequestMapping(\"\/api\/user\")\r\nclass UserController {\r\n\r\n    @Autowired\r\n    lateinit var userService: UserService\r\n\r\n    @GetMapping(value = \"\/{id}\")\r\n    fun findById(@PathParam(\"id\") id: String) = userService.findById(id)\r\n\r\n\r\n    @GetMapping(value = \"\/preference\")\r\n    fun findPreference(@RequestParam(\"name\") name: String): List&lt;User&gt; {\r\n        return userService.findUsersByPreferenceName(name)\r\n    }\r\n\r\n    @GetMapping(value = \"\/find\")\r\n    fun findUserByName(@RequestParam(\"name\") name: String): List&lt;User&gt; {\r\n        return userService.findByName(name)\r\n    }\r\n\r\n    @PostMapping(value = \"\/save\")\r\n    fun findUserByName(@RequestBody user: User) = userService.save(user)\r\n\r\n    @GetMapping(value = \"\/findByAddress\")\r\n    fun findByAddress(@RequestParam(\"streetName\", defaultValue = \"\") streetName: String,\r\n                      @RequestParam(\"number\", defaultValue = \"\") number: String,\r\n                      @RequestParam(\"postalCode\", defaultValue = \"\") postalCode: String,\r\n                      @RequestParam(\"city\", defaultValue = \"\") city: String,\r\n                      @RequestParam(\"country\", defaultValue = \"\") country: String): List&lt;User&gt; {\r\n        return userService.findUserByAddress(streetName, number, postalCode, city, country);\r\n    }\r\n\r\n}<\/pre>\n<h2><strong>Writing Integration Tests with Kotlin<\/strong><\/h2>\n<p>To run the integrations tests correctly, don\u2019t forget to configure the credentials of your database in the <strong>application.properties<\/strong> file:<\/p>\n<pre class=\"lang:default decode:true\">spring.couchbase.bootstrap-hosts=localhost\r\nspring.couchbase.bucket.name=test\r\nspring.couchbase.bucket.password=somePassword\r\nspring.data.couchbase.auto-index=true<\/pre>\n<p>Here, you can see how our tests look like:<\/p>\n<pre class=\"lang:default decode:true \">@Test\r\n    fun testComposedAddress() {\r\n        val address1 = Address(\"street1\", \"1\", \"0000\", \"santo andre\", \"br\")\r\n        val address2 = Address(\"street1\", \"2\", \"0000\", \"santo andre\", \"br\")\r\n        val address3 = Address(\"street2\", \"12\", \"1111\", \"munich\", \"de\")\r\n\r\n        userService.save(User(USER_1, \"user1\", address1, emptyList(), emptyList()))\r\n        userService.save(User(\"user::2\", \"user2\", address2, emptyList(), emptyList()))\r\n        userService.save(User(\"user::3\", \"user3\", address3, emptyList(), emptyList()))\r\n\r\n        var users = userService.findUserByAddress(streetName = \"street1\")\r\n        assertThat(users, hasSize&lt;Any&gt;(2))\r\n\r\n        users = userService.findUserByAddress(streetName = \"street1\", number=  \"1\")\r\n        assertThat(users, hasSize&lt;Any&gt;(1))\r\n\r\n        users = userService.findUserByAddress(country = \"de\")\r\n        assertThat(users, hasSize&lt;Any&gt;(1))\r\n    }<\/pre>\n<h3><strong>Kotlin and Maven Dependencies<\/strong><\/h3>\n<p>Kotlin is moving quickly, so be aware to use the most recent versions of each dependency:<\/p>\n<pre class=\"lang:xhtml decode:true \">    &lt;dependencies&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.jetbrains.kotlin&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;kotlin-stdlib-jdk8&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.2.41&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.jetbrains.kotlin&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;kotlin-reflect&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.2.41&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;com.fasterxml.jackson.module&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;jackson-module-kotlin&lt;\/artifactId&gt;\r\n            &lt;version&gt;2.9.5&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-boot-starter-data-couchbase&lt;\/artifactId&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-boot-starter-data-rest&lt;\/artifactId&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\r\n            &lt;scope&gt;test&lt;\/scope&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.hamcrest&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;hamcrest-library&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.3&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.springframework.data&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-data-couchbase&lt;\/artifactId&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.jetbrains.kotlin&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;kotlin-stdlib-jdk8&lt;\/artifactId&gt;\r\n            &lt;version&gt;${kotlin.version}&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.jetbrains.kotlin&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;kotlin-test&lt;\/artifactId&gt;\r\n            &lt;version&gt;${kotlin.version}&lt;\/version&gt;\r\n            &lt;scope&gt;test&lt;\/scope&gt;\r\n        &lt;\/dependency&gt;\r\n        &lt;dependency&gt;\r\n            &lt;groupId&gt;org.jetbrains.kotlin&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;kotlin-maven-allopen&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.2.41&lt;\/version&gt;\r\n        &lt;\/dependency&gt;\r\n    &lt;\/dependencies&gt;<\/pre>\n<p>You can view the whole <strong>pom.xml<\/strong> <a href=\"https:\/\/github.com\/couchbaselabs\/try-cb-kotlin\/blob\/master\/pom.xml\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year I started learning Kotlin and I was surprised at how easy it was to convert a Java application. IntelliJ and a few other IDEs offer nice tools for automatic conversion, and with a few adjustments you can end [&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":[1814,1815],"tags":[],"ppma_author":[9059],"class_list":["post-5267","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-best-practices-and-tutorials"],"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>Couchbase with Kotlin, Spring Boot and Spring Data<\/title>\n<meta name=\"description\" content=\"See how easy it is to convert a Java application. Check out how to create a sample application using: Kotlin, Spring Boot, Spring Data, and Couchbase.\" \/>\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\/kotlin-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 Kotlin, Spring Boot and Spring Data\" \/>\n<meta property=\"og:description\" content=\"See how easy it is to convert a Java application. Check out how to create a sample application using: Kotlin, Spring Boot, Spring Data, and Couchbase.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-11T10:01:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-20T21:48:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-1024x252.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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/\"},\"author\":{\"name\":\"Denis Rosa, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257\"},\"headline\":\"Couchbase with Kotlin, Spring Boot and Spring Data\",\"datePublished\":\"2018-06-11T10:01:59+00:00\",\"dateModified\":\"2023-07-20T21:48:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/\"},\"wordCount\":602,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"Application Design\",\"Best Practices and Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/\",\"name\":\"Couchbase with Kotlin, Spring Boot and Spring Data\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2018-06-11T10:01:59+00:00\",\"dateModified\":\"2023-07-20T21:48:34+00:00\",\"description\":\"See how easy it is to convert a Java application. Check out how to create a sample application using: Kotlin, Spring Boot, Spring Data, and Couchbase.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/kotlin-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\/kotlin-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 Kotlin, 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":"Couchbase with Kotlin, Spring Boot and Spring Data","description":"See how easy it is to convert a Java application. Check out how to create a sample application using: Kotlin, Spring Boot, Spring Data, and Couchbase.","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\/kotlin-spring-boot-spring-data\/","og_locale":"en_US","og_type":"article","og_title":"Couchbase with Kotlin, Spring Boot and Spring Data","og_description":"See how easy it is to convert a Java application. Check out how to create a sample application using: Kotlin, Spring Boot, Spring Data, and Couchbase.","og_url":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/","og_site_name":"The Couchbase Blog","article_published_time":"2018-06-11T10:01:59+00:00","article_modified_time":"2023-07-20T21:48:34+00:00","og_image":[{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-04-at-10.34.39-PM-1024x252.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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/"},"author":{"name":"Denis Rosa, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/fe3c5273e805e72a5294611a48f62257"},"headline":"Couchbase with Kotlin, Spring Boot and Spring Data","datePublished":"2018-06-11T10:01:59+00:00","dateModified":"2023-07-20T21:48:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/"},"wordCount":602,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["Application Design","Best Practices and Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/","url":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/","name":"Couchbase with Kotlin, Spring Boot and Spring Data","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2018-06-11T10:01:59+00:00","dateModified":"2023-07-20T21:48:34+00:00","description":"See how easy it is to convert a Java application. Check out how to create a sample application using: Kotlin, Spring Boot, Spring Data, and Couchbase.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/kotlin-spring-boot-spring-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/kotlin-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\/kotlin-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 Kotlin, 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\/5267","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=5267"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/5267\/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=5267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=5267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=5267"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=5267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}