JHipster Works with Spring Native!

Overview

Spring Native with JHipster

This repository contains five apps we (@joshlong and @mraible) used to figure out how to make Spring Native work with JHipster.

  • spring-native-webflux - no client, no db, just WebFlux

  • spring-native-mvc - no client, no db, just Spring MVC

  • angular-webflux - Angular client, no db

  • postgres-webflux - Angular, WebFlux, R2DBC + PostgreSQL

  • postgres-mvc - Angular, Spring MVC, JPA + PostgreSQL

You should be able to create a JHipster monolith with OIDC, then make the following changes.

  1. Modify pom.xml to add native, adjust dependencies, and disable devtools:

    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    
    <pluginRepository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
    ...
    
    <repackage.classifier/>
    <spring-native.version>0.10.4</spring-native.version>
    ...
    
    <!-- Comment out devtools -->
    <!--dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency-->
    
    <!-- If reactive, add the following to fix NoClassDefFoundError: org/springframework/web/servlet/config/annotation/WebMvcConfigurer -->
    <!-- Answer from https://stackoverflow.com/a/67426209/65681 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    ...
    
    <!-- Springfox doesn't have support for Spring Native yet, so comment out Springfox dependencies -->
    <!-- https://github.com/springfox/springfox/issues/3816 -->
    ...
    
    <!-- If reactive, comment out boringssl. This allows Spring Native to build the image and gets around this error:
        Error: Classes that should be initialized at run time got initialized during image building:
        io.netty.buffer.UnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time
        (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf).
        To see why io.netty.buffer.UnpooledUnsafeDirectByteB got initialized use
        trace-class-initialization=io.netty.buffer.UnpooledUnsafeDirectByteBuf
    -->
    <!--dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-tcnative-boringssl-static</artifactId>
    </dependency-->
    
    <dependency>
        <groupId>org.springframework.experimental</groupId>
        <artifactId>spring-native</artifactId>
        <version>${spring-native.version}</version>
    </dependency>
    
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <classifier>${repackage.classifier}</classifier>
            <image>
                <builder>paketobuildpacks/builder:tiny</builder>
                <env>
                    <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                </env>
            </image>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.springframework.experimental</groupId>
        <artifactId>spring-aot-maven-plugin</artifactId>
        <version>${spring-native.version}</version>
        <executions>
            <execution>
                <id>test-generate</id>
                <goals>
                    <goal>test-generate</goal>
                </goals>
            </execution>
            <execution>
                <id>generate</id>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    
    <profile>
        <id>native</id>
        <properties>
            <repackage.classifier>exec</repackage.classifier>
            <native-buildtools.version>0.9.3</native-buildtools.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>junit-platform-native</artifactId>
                <version>${native-buildtools.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.graalvm.buildtools</groupId>
                    <artifactId>native-maven-plugin</artifactId>
                    <version>${native-buildtools.version}</version>
                    <executions>
                        <execution>
                            <id>test-native</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>build-native</id>
                            <phase>package</phase>
                            <goals>
                                <goal>build</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
  2. Remove the 127.0.0.1 prefix from keycloak.yml

  3. Delete spring-logback.xml and tone down logging

    logging:
      level:
        root: ERROR
  4. If reactive, update LocaleConfiguration.java to remove @Import(WebFluxAutoConfiguration.class)

  5. Update main App.java to add hints (first four of each list only required for reactive)

    @NativeHint(options = "--enable-url-protocols=http,https")
    @TypeHint(
        types = {
            ReactiveOAuth2AuthorizedClientManager.class,
            ReactiveOAuth2AuthorizedClientProviderBuilder.class,
            DefaultReactiveOAuth2AuthorizedClientManager.class,
            AbstractWebClientReactiveOAuth2AccessTokenResponseClient.class,
            liquibase.configuration.LiquibaseConfiguration.class,
            com.zaxxer.hikari.HikariDataSource.class,
            liquibase.change.core.LoadDataColumnConfig.class,
            org.HdrHistogram.Histogram.class,
            org.HdrHistogram.ConcurrentHistogram.class,
        },
        typeNames = {
            "org.springframework.web.reactive.function.client.DefaultWebClientBuilder",
            "reactor.core.publisher.Traces$StackWalkerCallSiteSupplierFactory",
            "reactor.core.publisher.Traces$SharedSecretsCallSiteSupplierFactory",
            "reactor.core.publisher.Traces$ExceptionCallSiteSupplierFactory",
            "com.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry[]"
        },
        access = AccessBits.ALL)
  6. Liquibase is not supported yet, but you can make it work by adding files from this pull request to your src/main/resources/META-INF/native-image/liquibase directory

  7. Add an @AotProxyHint for each Resource classes

    @AotProxyHint(targetClass = UserResource.class, proxyFeatures = ProxyBits.IS_STATIC)
    @AotProxyHint(targetClass = BlogResource.class, proxyFeatures = ProxyBits.IS_STATIC)
    @AotProxyHint(targetClass = PostResource.class, proxyFeatures = ProxyBits.IS_STATIC)
    @AotProxyHint(targetClass = TagResource.class, proxyFeatures = ProxyBits.IS_STATIC)
  8. If using Spring WebFlux, refactor repositories and add @AotProxyHint for each one

  9. If using Spring MVC, swap Undertow dependencies for Tomcat, modify WebConfigurer to comment out setLocationForStaticAssets(server), and add additional type hints for the following classes:

    • tech.jhipster.domain.util.FixedPostgreSQL10Dialect.class

    • org.hibernate.type.TextType.class

  10. Build with ./mvnw package -Pnative,prod -DskipTests

Known Issues

  • Springfox (Swagger) doesn’t work

  • Metrics don’t work

  • Repositories need refactoring for R2DBC

You might also like...

Spring-boot application to demo JVM HEAP and Native memory leak

Description This repo can be used as demo repo for finding memory leaks. Example spring-boot project to show how to find and fix JVM HEAP memory leak

Jul 22, 2022

一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

友情提示:因为提供了 50000+ 行示例代码,所以艿艿默认注释了所有 Maven Module。 胖友可以根据自己的需要,修改 pom.xml 即可。 一个涵盖六个主流技术栈的正经仓库: 《Spring Boot 专栏》 《Spring Cloud Alibaba 专栏》 《Spring Clou

Dec 31, 2022

参考 DDD/Clean Architecture 设计理念,整合 Spring Boot/Spring Security/Mybatis Plus/Vavr 的 Spring Realworld 应用案例

参考 DDD/Clean Architecture 设计理念,整合 Spring Boot/Spring Security/Mybatis Plus/Vavr 的 Spring Realworld 应用案例

Demo · 更多项目 · 参考资料 ms-spring-ddd-examples Unified Domain-driven Layered Architecture for MicroService Apps,试图探索一套切实可行的应用架构规范,可以复制、可以理解、可以落地、可以控制复杂性的指导

Sep 23, 2022

Spring Kurulumundan Başlayarak, Spring IOC ve Dependency Injection, Hibernate, Maven ve Spring Boot Konularına Giriş Yapıyoruz.

Spring Kurulumundan Başlayarak, Spring IOC ve Dependency Injection, Hibernate, Maven ve Spring Boot Konularına Giriş Yapıyoruz.

Spring Tutorial for Beginners File Directory Apache Tomcat Apache Tomcat - Eclipse Bağlantısı Spring Paketlerinin İndirilmesi ve Projeye Entegrasyonu

Apr 11, 2022

Spring Boot JdbcTemplate example with SQL Server: CRUD Rest API using Spring Data JDBC, Spring Web MVC

Spring Boot JdbcTemplate example with SQL Server: Build CRUD Rest API Build a Spring Boot CRUD Rest API example that uses Spring Data Jdbc to make CRU

Dec 20, 2022

Spring Boot & MongoDB Login and Registration example with JWT, Spring Security, Spring Data MongoDB

Spring Boot & MongoDB Login and Registration example with JWT, Spring Security, Spring Data MongoDB

Spring Boot Login and Registration example with MongoDB Build a Spring Boot Auth with HttpOnly Cookie, JWT, Spring Security and Spring Data MongoDB. Y

Dec 30, 2022

Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

Jan 5, 2023

Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

Sep 13, 2022

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Jan 26, 2022
Comments
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /angular-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-mvc/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | | | | | | Total : | 759.25kb | 737.89kb | 2.81% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /angular-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-mvc/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | | | | | | Total : | 759.25kb | 737.89kb | 2.81% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /postgres-mvc/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /angular-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | | | | | | Total : | 759.25kb | 737.89kb | 2.81% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced!

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /postgres-mvc/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /angular-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-webflux/src/main/webapp/swagger-ui/dist/images/throbber.gif | 9.04kb | 5.97kb | 33.94% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_1.svg | 221.98kb | 218.01kb | 1.79% | | /postgres-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /angular-webflux/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | /postgres-mvc/src/main/webapp/content/images/jhipster_family_member_2.svg | 22.07kb | 21.98kb | 0.39% | | | | | | | Total : | 759.25kb | 737.89kb | 2.81% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
Releases(v0.1)
Owner
Matt Raible
Web Developer, Java Champion, and @oktadeveloper with a passion for skiing, mountain biking, classic VWs, and good 🍺. Frequent contributor to @jhipster! 🤓
Matt Raible
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
JHipster Lite ⚡ is a development platform to generate, develop & deploy modern web applications & microservice architectures, step by step.

JHipster Lite ⚡ Description JHipster is a development platform to quickly generate, develop & deploy modern web applications & microservice architectu

JHipster 255 Jan 3, 2023
Version-agnostic and package-agnostic interfaces used in Constellar. Zero strict dependencies, works as a submodule.

bridge Version-agnostic and package-agnostic interfaces used in Constellar. Zero strict dependencies, works as a submodule. Used for cross-compatibili

uranometrical 2 Feb 23, 2022
Sceneform React Native AR Component using ARCore and Google Filament as 3D engine. This the Sceneform Maintained Component for React Native

Discord Server Join us on Discord if you need a hand or just want to talk about Sceneform and AR. Features Remote and local assets Augmented Faces Clo

SceneView Open Community 42 Dec 17, 2022
React native wrapper for Jitsi Meet SDK Library that rely on the native view (Activity / ViewController)

react-native-jitsi-meet-sdk React native wrapper for Jitsi Meet SDK Library. This Library implements the Jitsi SDK with a native activity on the Andro

null 7 May 2, 2022
With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any other file server

React Native In-App update With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any o

Nepein Andrey 7 Dec 21, 2022
An awesome native wheel picker component for React Native.

⛏️ react-native-picky An awesome native wheel picker component for react-native. Features Supports multiple columns ✅ Supports looping ✅ Native Androi

null 28 Dec 4, 2022
Spring JPA Native Query example in Spring Boot

Spring JPA Native Query example in Spring Boot

null 12 Nov 30, 2022
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
Fabric8 Spring Native Integrations

Fabric8 Spring Native Integrations Earlier, I wrote an example on how to get Spring Native and the official Kubernetes Native Java client working with

Kubernetes Native Java 11 Mar 7, 2022