Java中MapStruct映射处理器报错的问题解决
引言
MapStruct是一个强大的Java映射框架,它能够在编译时生成映射代码,提高了映射的性能。然而,有时候在使用MapStruct时可能会遇到一些问题,其中之一就是java: Internal error in the mapping processor: java.lang.NullPointerException
错误。
错误原因
这个错误通常是由于MapStruct在处理映射时出现了空指针异常引起的。可能的原因是:
版本兼容性问题: 使用不兼容的MapStruct版本可能导致内部处理器错误。
<!--MapStruct 依赖--> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>1.3.1.Final</version> </dependency> <!--MapStruct 注解处理器--> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.3.1.Final</version> </dependency>
java: Internal error in the mapping processor: java.lang.NullPointerException at org.mapstruct.ap.internal.processor.DefaultVersionInformation.createManifestUrl(DefaultVersionInformation.java:182) at org.mapstruct.ap.internal.processor.DefaultVersionInformation.openManifest(DefaultVersionInformation.java:153) at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getLibraryName(DefaultVersionInformation.java:129) at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getCompiler(DefaultVersionInformation.java:122) at org.mapstruct.ap.internal.processor.DefaultVersionInformation.fromProcessingEnvironment(DefaultVersionInformation.java:95) at org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext.<init>(DefaultModelElementProcessorContext.java:50) at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:218) at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:156) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jetbrains.jps.javac.APIWrappers$1.invoke(APIWrappers.java:248) at org.mapstruct.ap.MappingProcessor.process(Unknown Source) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856) at com.sun.tools.javac.main.Main.compile(Main.java:523) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138) at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231) at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:501) at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:353) at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:277) at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:231) at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1441) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1224) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:832) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:419) at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183) at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132) at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302) at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132) at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748)
解决方案
将 MapStruct 更新到 1.4.1.Final
或更高版本
<!--MapStruct 依赖--> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>1.4.1.Final</version> </dependency> <!--MapStruct 注解处理器--> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.4.1.Final</version> </dependency>
如果还出现以下错误
java:No property named "xxx" exists in source parameter(s). Did you mean "null"?
引入依赖解决
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </dependency>
到此这篇关于Java中MapStruct映射处理器报错的问题解决的文章就介绍到这了,更多相关Java MapStruct映射处理器报错内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
spring boot中controller的使用及url参数的获取方法
这篇文章主要介绍了spring boot中controller的使用及url参数的获取方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下2018-01-01Java实现前端jsencrypt.js加密后端解密的示例代码
这篇文章主要为大家详细介绍了如何利用jsencrypt.js实现前端加密,利用Java实现后端解密的功能,文中的示例代码讲解详细,需要的可以参考一下2022-09-09idea中增强for循环提示unexpected token问题
这篇文章主要介绍了idea中增强for循环提示unexpected token问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-01-01Spring探秘之如何妙用BeanPostProcessor
BeanPostProcessor也称为Bean后置处理器,它是Spring中定义的接口,在Spring容器的创建过程中会回调BeanPostProcessor中定义的两个方法,这篇文章主要给大家介绍了关于Spring探秘之如何妙用BeanPostProcessor的相关资料,需要的朋友可以参考下2022-01-01Spring Boot + Vue 前后端分离项目如何踢掉已登录用户
这篇文章主要介绍了Spring Boot + Vue 前后端分离项目如何踢掉已登录用户,需要的朋友可以参考下2020-05-05spring boot配置dubbo方式(properties)
这篇文章主要介绍了spring boot配置dubbo方式(properties),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-01-01
最新评论