Building Applications with Spring 5 and Kotlin
eBook - ePub

Building Applications with Spring 5 and Kotlin

Build scalable and reactive applications with Spring combined with the productivity of Kotlin

  1. 310 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Building Applications with Spring 5 and Kotlin

Build scalable and reactive applications with Spring combined with the productivity of Kotlin

About this book

Learn to build a full-fledged application in Spring and Kotlin taking a reactive, microservice-based approach for scalability and robustness in the cloudAbout This Book• Build a full-fledged application in Spring and Kotlin• Architect your application to take a microservice-based approach in the cloud• Integrate your application with a variety of Spring componentsWho This Book Is ForDevelopers comfortable using Spring who have basic knowledge of Kotlin and want to take their development skills to the next level and build enterprise-grade applications will benefit from this book.What You Will Learn• Explore Spring 5 concepts with Kotlin• Learn both dependency injections and complex configurations• Utilize Spring Data, Spring Cloud, and Spring Security in your applications• Create efficient reactive systems with Project Reactor• Write unit tests for your Spring/Kotlin applications• Deploy applications on cloud platforms like AWSIn DetailKotlin is being used widely by developers because of its light weight, built-in null safety, and functional and reactive programming aspects. Kotlin shares the same pragmatic, innovative and opinionated mindset as Spring, so they work well together. Spring when combined with Kotlin helps you to reach a new level of productivity. This combination has helped developers to create Functional Applications using both the tools together. This book will teach you how to take advantage of these developments and build robust, scalable and reactive applications with ease.In this book, you will begin with an introduction to Spring and its setup with Kotlin. You will then dive into assessing the design considerations of your application. Then you will learn to use Spring (with Spring Boot) along with Kotlin to build a robust backend in a microservice architecture with a REST based collaboration, and leverage Project Reactor in your application. You'll then learn how to integrate Spring Data and Spring Cloud to manage configurations for database interaction and cloud deployment. You'll also learn to use Spring Security to beef up security of your application before testing it with the JUnit framework and then deploying it on a cloud platform like AWS.Style and approachEverything you learn will be demonstrated on real-world Spring project. In each chapter we will cover some of Spring features and apply it on our project. We will guide you from the project initialization till the project deployment.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Building Applications with Spring 5 and Kotlin by Milos Vasic in PDF and/or ePUB format, as well as other popular books in Computer Science & Cloud Computing. We have over one million books available in our catalogue for you to explore.

Information

Project Deployment

We have reached the end of our journey. In the previous chapter, we wrote some tests to confirm that our code is working properly. In this chapter, we will release our Spring application into production. We will cover examples of how to publish it step by step and provide you with guidelines and advice for further reading on this subject.
In this final chapter of the book, we will cover the following:
  • What will be deployed?
  • Deployment options
  • Deploying to the Cloud (AWS)

What will be deployed?

Before we deploy anything, we must provide everything that will be deployed. For this, we will deploy the JAR of our API module. The JAR is a result of application building. The first thing we will do is prepare our application for release. We will change our port from 9000 to 80. Open the application.properties file and make the following changes:
spring.application.name= journaler server.port= 80 logging.level.root=INFO logging.level.com.journaler.api=DEBUG logging.level.org.springframework.jdbc=ERROR endpoints.health.enabled=true endpoints.trace.enabled=true endpoints.info.enabled=true endpoints.metrics.enabled=true spring.datasource.url=jdbc:mysql://localhost/journaler_api?useSSL=false&useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=localInstance2017 spring.datasource.tomcat.test-on-borrow=true spring.datasource.tomcat.validation-interval=30000 spring.datasource.tomcat.validation-query=SELECT 1 spring.datasource.tomcat.remove-abandoned=true spring.datasource.tomcat.remove-abandoned-timeout=10000 spring.datasource.tomcat.log-abandoned=true spring.datasource.tomcat.max-age=1800000 spring.datasource.tomcat.log-validation-errors=true spring.datasource.tomcat.max-active=50 spring.datasource.tomcat.max-idle=10 spring.jpa.hibernate.ddl-auto=update 
The next thing we need to do is clean the project by executing the ./gradlew clean command as shown in the following screenshot:
The output of the preceding command is as shown in the following screenshot:
Now, we will perform ./gradlew assemble to build the application:
The output of the preceding command is as shown in the following screenshot:
Let's list the content of our project directory by executing the ls command:
Navigate to build/libs directory and list the content of the directory using the ls
command, as shown in the following screenshot:
Copy the JAR you see to the location where you want to save it. We will copy it to the Desktop for the current user, as shown in the following screenshot:
Now, navigate to the location where you just copied the JAR file and try to run it as shown in the following screenshot:
As you can see in the following screenshot, this will fail:
To be able to run our application on port 80, you must run it as a sudo user, as shown in the following screenshot:
You will be asked for your user's password. Type it in and hit Enter. The application will run, as shown in the following screenshot:
Once again, confirm that everything works properly. Open Postman and trigger a couple of API calls, targeting the local host on port 80.
We will insert some notes here:
And we will read them:
Once we are sure that this build is fine, we can proceed to the next step in our deployment mission.

Deployment options

In thi...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Starting Up
  7. Starting with Spring
  8. Building Your First Spring RESTful Service with Kotlin
  9. Working with Spring Data JPA and MySQL
  10. Securing Applications with Spring Security
  11. Spring Cloud
  12. Using Project Reactor
  13. Development Practices
  14. Testing
  15. Project Deployment
  16. Other Books You May Enjoy