国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot快速遷移至Quarkus的方法步驟

瀏覽:97日期:2023-03-29 09:27:43

Quarkus 是一個目前非常火的 Java 應(yīng)用開發(fā)框架,定位是輕量級的微服務(wù)框架。,Quarkus 提供了優(yōu)秀的容器化整合能力,相較于傳統(tǒng)開發(fā)框架(Spring Boot)有著更快的啟動速度、更小的內(nèi)存消耗、更短的服務(wù)響應(yīng)。

SpringBoot快速遷移至Quarkus的方法步驟

本文將演示將 SpringBoot 遷移至 Quarkus

Spring Boot 示例程序

使用 JPA 完成 數(shù)據(jù)庫的增刪改查操作,基礎(chǔ)代碼如下

maven 依賴

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>

jpa crud

public interface DemoUserDao extends CrudRepository<DemoUser, Long> {}遷移至 Quarkus

quarkus-bom 管理了全部 quarkus 插件 maven 依賴的版本信息,引入后所有依賴不需要再定義版本。

<dependencyManagement> <dependencies> <dependency><groupId>io.quarkus</groupId><artifactId>quarkus-bom</artifactId><version>1.10.5.Final</version><type>pom</type><scope>import</scope> </dependency> </dependencies> </dependencyManagement>

遷移 spring-web 、spring-jpa 至 quarkus 技術(shù)棧。

<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-spring-data-jpa</artifactId></dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-spring-web</artifactId></dependency>

配置文件調(diào)整 (還是在 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

Main 方法調(diào)整為 實現(xiàn) QuarkusApplication ,且需要通過 Quarkus.waitForExit() 保持服務(wù)運行。

@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; }}啟動運行

main 方法啟動, 輸出 Quarkus banner

__ ____ __ _____ ___ __ ____ ______ --/ __ / / / / _ | / _ / //_/ / / / __/ -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ / --________/_/ |_/_/|_/_/|_|____/___/2021-01-12 22:31:46,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:31:48,702 INFO [io.quarkus] (Quarkus Main Thread) Quarkus 1.10.5.Final on JVM started in 4.613s. Listening on: http://localhost:80802021-01-12 22:31:48,703 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.2021-01-12 22:31:48,703 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]

非常重要的是輸出了當前已經(jīng)安裝的功能

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]【擴展】 actuator 監(jiān)控遷移

添加以下依賴

<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId></dependency>

指定訪問監(jiān)控斷點路徑

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

訪問監(jiān)控檢查斷點測試

curl http://localhost:8080/actuator/health{ 'status': 'UP', 'checks': [ { 'name': 'Database connections health check', 'status': 'UP' } ]}⏎【擴展】Flyway 遷移

添加 quarkus flyway 插件

<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-flyway</artifactId></dependency>

指定插件啟動策略即可

quarkus.flyway.migrate-at-start=true

>>> 源碼 https://gitee.com/log4j/pig

到此這篇關(guān)于SpringBoot快速遷移至Quarkus的方法步驟的文章就介紹到這了,更多相關(guān)SpringBoot 遷移至Quarkus內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 明溪县| 攀枝花市| 乳源| 客服| 张家港市| 陕西省| 洪洞县| 汉寿县| 东阿县| 襄汾县| 承德市| 清苑县| 军事| 周至县| 安溪县| 中西区| 衡东县| 阳原县| 南乐县| 江油市| 定远县| 许昌县| 隆子县| 高台县| 出国| 高清| 玉田县| 清远市| 隆林| 乐山市| 谷城县| 元氏县| 陇西县| 广丰县| 丹东市| 许昌市| 都江堰市| 集贤县| 莒南县| 易门县| 乾安县|