恒美微站 Logo 恒美微站
  • 首页
  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心
  • 联系我们

Springboot4项目构建原生镜像的问题解决(持续更新,请收藏)

  • 首页
  • 资讯中心
  • /
  • Springboot4项目构建原生镜像的问题解决(持续更新,请收藏)

相关资讯

Reloaded-II Mod加载器故障急救指南:7个实测有效的自救方案 2026/8/19 10:55:51
机器人关节角度传感器:从编码器原理到伺服控制实战 2026/8/19 10:55:51
AgileLog:为数据流智能体设计的可复刻共享日志架构解析 2026/8/19 10:55:51

最新资讯

Navicat无限试用完整指南:3种重置方案速查表,告别14天限制
【vemory】增量持久化方案设计
CircuitJS1 离线电路仿真软件教程:免费开源,四步构建,零基础跑通第一张电路图
免费完整攻略:5 步学会抖音批量下载,无水印视频、音乐、直播一次拿下
免费游戏串流终极指南:用 Sunshine 把主机游戏搬到客厅电视
如何让老旧电脑免费升级Windows 11?MediaCreationTool.bat一站式实战指南

今日推荐

Windows 安卓应用安装终极方案:5分钟上手免费APK安装器,三步告别模拟器
WarcraftHelper 魔兽争霸3优化实战指南
抖音批量下载实战手册:用douyin-downloader把6小时手工劳动压缩到15分钟

本周热门

【文章复现】非线性值迭代自适应动态规划(ADP):离散时间非线性系统的策略迭代自适应动态规划算法研究附Matlab代码
【双层规划,节点出清价,绿证交易,CVaR方法】两级电力市场环境下计及风险的省间交易商最优购电模型附Matlab代码
隐式mpc+自适应mpc+时变mpc,线性时变模型预测控制附Simulink仿真

本月精选

如何用DamaiHelper实现演唱会门票的智能自动化抢购:完整技术解决方案指南
第4篇:59 倍性能差距的索引瓶颈定位——一次教科书级的全表扫描调优
终极歌词批量下载神器:5分钟解决离线音乐库歌词同步难题

Springboot4项目构建原生镜像的问题解决(持续更新,请收藏)

发布时间:2026/8/19 11:00:51
Springboot4项目构建原生镜像的问题解决(持续更新,请收藏) 一个项目升级到springboot4构建成原生镜像后各种问题经过一番摸索终于解决了。1、ehcache配置问题异常信息Caused by: org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/workspace/config-common/ehcache3.xml at org.ehcache.xml.XmlConfiguration.init(XmlConfiguration.java:127) at org.ehcache.xml.XmlConfiguration.init(XmlConfiguration.java:93) at org.ehcache.jsr107.EhcacheCachingProvider$ConfigSupplier.getConfiguration(EhcacheCachingProvider.java:346) ... 160 more Caused by: javax.xml.bind.JAXBException - with linked exception: [java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext([Ljava.lang.Class;, java.util.Map)] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:305) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:286) at javax.xml.bind.ContextFinder.find(ContextFinder.java:409) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) at org.ehcache.xml.ConfigurationParser.init(ConfigurationParser.java:118) at org.ehcache.xml.XmlConfiguration.init(XmlConfiguration.java:117) ... 162 more解决方法JAXB 实现版本不匹配需要确保引入的 JAXB 实现与 Ehcache 3 兼容并且支持 Native。但我正好想更换成redis缓存所以直接更换了。2、问题如下Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user ${spring.datasource.username} at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:835) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:307) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:365) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:52) at org.postgresql.jdbc.PgConnection.init(PgConnection.java:290)我是在一个配置文件里配置了spring.datasource.username另一个配置文件引用这个变量构建原生镜像后它解析不了这个值。解决方法是设置两个环境变量DB_USER, DB_PASSWORD这样在K8S里还可以加密比较好。3、各类ClassNotFound异常如Caused by: java.lang.IllegalStateException: Cannot load driver class: com.xcmg.finance.tmp.common.datasource.DynamicDataSource at org.springframework.util.Assert.state(Assert.java:102) at org.springframework.boot.jdbc.autoconfigure.DataSourceProperties.findDriverClassName(DataSourceProperties.java:187) at org.springframework.boot.jdbc.autoconfigure.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:177) at org.springframework.boot.jdbc.autoconfigure.PropertiesJdbcConnectionDetails.getDriverClassName(PropertiesJdbcConnectionDetails.java:51) at org.springframework.boot.jdbc.autoconfigure.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:63)这类异常很是头疼摸索了很久终于知道原因Springboot4构建 原生镜像时会先启动应用根据启动应用用到了哪些构件它会把相应的构件包含进去用不到的会被丢弃所以我们要设置一个正确的profiles.active让它把正式启动时用到的所有类都加载进去。解决方法设置一个环境变量再构建exportSPRING_PROFILES_ACTIVEcommon,logging,local,logging mvn spring-boot:build-image-Dmaven.test.skiptrue-Pxcmg,native4、方法不允许反射的问题Caused by: org.graalvm.nativeimage.MissingReflectionRegistrationError: Cannot reflectively invoke method public void com.zaxxer.hikari.HikariConfig.setDriverClassName(java.lang.String). To allow this operation, add the following to the reflection section of reachability-metadata.json and rebuild the native image: { type: com.zaxxer.hikari.HikariConfig, methods: [ { name: setDriverClassName, parameterTypes: [ java.lang.String ] } ] } The reachability-metadata.json file should be located in META-INF/native-image/group-id/artifact-id/ of your project. For further help, see https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.reportInvokedExecutable(MissingReflectionRegistrationUtils.java:110)解决方法添加一个文件META-INF/native-image///reachability-metadata.json内容如下{ reflection: [ { type: com.zaxxer.hikari.HikariConfig, allDeclaredConstructors: true, allDeclaredMethods: true, allPublicConstructors: true, allPublicMethods: true, fields: [ { name: driverClassName, allowWrite: true }, { name: jdbcUrl, allowWrite: true }, { name: username, allowWrite: true }, { name: password, allowWrite: true }, { name: maximumPoolSize, allowWrite: true }, { name: minimumIdle, allowWrite: true }, { name: idleTimeout, allowWrite: true }, { name: connectionTimeout, allowWrite: true }, { name: validationTimeout, allowWrite: true }, { name: maxLifetime, allowWrite: true }, { name: poolName, allowWrite: true } ] }, { type: com.zaxxer.hikari.HikariDataSource, allDeclaredConstructors: true, allDeclaredMethods: true, allPublicConstructors: true, allPublicMethods: true }, { type: org.postgresql.Driver, allDeclaredConstructors: true, allDeclaredMethods: true }, { type: org.postgresql.jdbc.PgDriver, allDeclaredConstructors: true, allDeclaredMethods: true } ] }我的完整路径src/main/resources/META-INF/native-image/com.xcmg.finance.tmp/tmp-base-service/tmp-base-service/reachability-metadata.json5、类在heap中找不到日志如下[INFO] [creator] Fatal error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type org.apache.logging.slf4j.SLF4JServiceProvider was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default. [INFO] [creator] This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time. [INFO] [creator] [INFO] [creator] You now have two options to resolve this: [INFO] [creator] [INFO] [creator] 1) If it is intended that objects of type org.apache.logging.slf4j.SLF4JServiceProvider are persisted in the image heap, add [INFO] [creator] [INFO] [creator] --initialize-at-build-timeorg.apache.logging.slf4j.SLF4JServiceProvider [INFO] [creator] [INFO] [creator] to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of org.apache.logging.slf4j.SLF4JServiceProvider to see if they are safe for build-time initialization, and that they do not contain any sensitive data that should not become part of the image. [INFO] [creator] [INFO] [creator] 2) If these objects should not be stored in the image heap, you can use [INFO] [creator] [INFO] [creator] --trace-object-instantiationorg.apache.logging.slf4j.SLF4JServiceProvider [INFO] [creator]解决方法在spring-boot-maven plugin中添加参数把相应的包名加进去。如plugin groupIdorg.springframework.boot/groupId artifactIdspring-boot-maven-plugin/artifactId version${spring-boot.version}/version executions execution goals goalrepackage/goal /goals /execution /executions configuration image !-- 自定义应用镜像名称可选 -- name10.16.10.28:8085/tmp/${project.artifactId}:${project.version}/name env BP_DEPENDENCY_MIRRORhttps://irmp.xcmglease.com:9443/download/BP_DEPENDENCY_MIRROR BP_NATIVE_IMAGE_BUILD_ARGUMENTS--initialize-at-build-timeorg.springframework.boot.logging.log4j,org.slf4j,org.apache.logging.slf4j,org.apache.logging.log4j,io.netty.util.internal.logging --initialize-at-run-timeio.lettuce.core.resource.KqueueProvider,io.netty.util.internal.SystemPropertyUtil,com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration/BP_NATIVE_IMAGE_BUILD_ARGUMENTS JAVA_TOOL_OPTIONS-Dfile.encodingUTF-8 -Duser.timezoneAsia/Shanghai -XX:MaxRAMPercentage75.0 -XX:InitialRAMPercentage50.0 -XX:MaxMetaspaceSize512m -XX:UseStringDeduplication -XX:ExitOnOutOfMemoryError -Dspring.aot.enabledtrue -XX:PrintCommandLineFlags/JAVA_TOOL_OPTIONS /env /image /configuration /plugin本类错误会很多出现一个加一个包名进去再试就好了。

关于恒美微站

恒美微站专注于为个体商户、工作室提供极简自助建站服务,让每个人都能轻松拥有专业网站。

快速链接

  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心

服务项目

  • 可视化建站
  • 拖拽编辑
  • 主题定制
  • SEO 优化
  • 网站托管

联系方式

  • 📍 地址:北京市朝阳区建国路 88 号
  • 📞 电话:400-888-8888
  • ✉️ 邮箱:info@hmyw.cn
  • 🕐 时间:周一至周日 9:00-18:00

© 2024 恒美微站 hmyw.cn 版权所有 | 京 ICP 备 12345678 号