Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly migrate Spring Boot to Quarkus

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to quickly migrate Spring Boot to Quarkus". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to quickly migrate Spring Boot to Quarkus.

Quarkus is a very popular Java application development framework, positioning as a lightweight micro-service framework. Quarkus provides excellent containerization integration capability, which has faster startup speed, less memory consumption and shorter service response than traditional development framework (Spring Boot).

This article will demonstrate the migration of SpringBoot to Quarkus

Spring Boot sample program

Use JPA to add, delete, modify and query the database. The basic code is as follows

Maven dependence

Org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web

Jpa crud

Public interface DemoUserDao extends CrudRepository {} migrate to Quarkus

Quarkus-bom manages the version information of all quarkus plug-in maven dependencies, and all dependencies do not need to be defined after introduction.

Io.quarkus quarkus-bom 1.10.5.Final pom import

Migrate spring-web, spring-jpa to quarkus technology stack.

Io.quarkus quarkus-spring-data-jpa io.quarkus quarkus-spring-web

Profile adjustment (again in application.yml)

Quarkus.datasource.db-kind=mysqlquarkus.datasource.jdbc.driver=com.mysql.cj.jdbc.Driverquarkus.datasource.username=rootquarkus.datasource.password=rootquarkus.datasource.jdbc.url=jdbc:mysql://localhost:3306/pig_demo?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE

The Main method is adjusted to implement QuarkusApplication, and you need to keep the service running through Quarkus.waitForExit ().

@ QuarkusMainpublic class SimpleApplication implements QuarkusApplication {public static void main (String [] args) {Quarkus.run (SimpleApplication.class,args);} @ Override public int run (String... Args) {Quarkus.waitForExit (); return 0;}} start running

The main method starts and outputs Quarkus banner

_ / _ / / _ _ / / _ _ / / / < / / _ / /\\--\ _ / / | _ / _ / | _ / _ / | _ _ / _ _ / 2021-01-12 22 22 build-21 341 INFO [io.qua.arc.pro.BeanProcessor] (build-21) Found unrecommended usage of private members (use package-private instead) in application beans:-@ Inject field com.example.simple.controller.DemoController#userDao2021-01-12 22 Quarkus Main Thread 31 INFO 48702 [io.quarkus] (Quarkus Main Thread) Quarkus 1.10.5.Final on JVM started in 4.613s. Listening on: http://localhost:80802021-01-12 22 INFO 31 INFO 48703 [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.2021-01-12 22 31D INFO [io.quarkus] (Quarkus Main Thread) Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, mutiny, narayana-jta, resteasy, resteasy-jackson, smallrye-context-propagation, spring-data-jpa, spring-di, spring-web]

It is very important to output the features that are currently installed

Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, mutiny, narayana-jta, resteasy, resteasy-jackson, smallrye-context-propagation, spring-data-jpa, spring-di, spring-web] [extension] actuator monitors migration

Add the following dependencies

Io.quarkus quarkus-smallrye-health

Specify the access monitoring breakpoint path

Quarkus.smallrye-health.root-path=/actuator/health

Access monitoring check breakpoint test

Curl http://localhost:8080/actuator/health{ "status": "UP", "checks": [{"name": "Database connections health check", "status": "UP"}]} ⏎ [extension] Flyway migration

Add a quarkus flyway plug-in

Io.quarkus quarkus-flyway

Just specify the plug-in startup strategy

Quarkus.flyway.migrate-at-start=true so far, I believe you have a deeper understanding of "how to quickly migrate Spring Boot to Quarkus". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report