SpringBoot快速遷移至Quarkus的方法步驟
Quarkus 是一個(gè)目前非常火的 Java 應(yīng)用開發(fā)框架,定位是輕量級的微服務(wù)框架。,Quarkus 提供了優(yōu)秀的容器化整合能力,相較于傳統(tǒng)開發(fā)框架(Spring Boot)有著更快的啟動速度、更小的內(nèi)存消耗、更短的服務(wù)響應(yīng)。
本文將演示將 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)整為 實(shí)現(xiàn) QuarkusApplication ,且需要通過 Quarkus.waitForExit() 保持服務(wù)運(yùn)行。
@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; }}啟動運(yùn)行
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]
非常重要的是輸出了當(dāng)前已經(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]【擴(kuò)展】 actuator 監(jiān)控遷移
添加以下依賴
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId></dependency>
指定訪問監(jiān)控?cái)帱c(diǎn)路徑
quarkus.smallrye-health.root-path=/actuator/health
訪問監(jiān)控檢查斷點(diǎn)測試
curl http://localhost:8080/actuator/health{ 'status': 'UP', 'checks': [ { 'name': 'Database connections health check', 'status': 'UP' } ]}⏎【擴(kuò)展】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)!
相關(guān)文章:
1. python實(shí)現(xiàn)讀取類別頻數(shù)數(shù)據(jù)畫水平條形圖案例2. 關(guān)于HTML5的img標(biāo)簽3. php5.6不能擴(kuò)展redis.so的解決方法4. python 爬取嗶哩嗶哩up主信息和投稿視頻5. CSS3實(shí)現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效6. python 如何停止一個(gè)死循環(huán)的線程7. ASP.NET MVC前臺動態(tài)添加文本框并在后臺使用FormCollection接收值8. JSP動態(tài)實(shí)現(xiàn)web網(wǎng)頁登陸和注冊功能9. Java 基于UDP協(xié)議實(shí)現(xiàn)消息發(fā)送10. PHP獲取時(shí)間戳等相關(guān)函數(shù)匯總
