升级到Spring Boot 3后mapstruct生成文件中的Javax依赖

问题描述 投票:0回答:1

我的任务是升级我们中心的一项 Rest 服务,以便它使用 Spring Boot 3。其中,我删除了所有 javax 导入,并用 jakarta 导入替换它们。 但是当我 Maven 打包我的应用程序时,我在生成的文件之一中获得了 javax 导入。

具体来说,导入是在这个生成的类中(如果这个类的实现对于描绘问题很重要,我将添加它):

import cz.cvut.fel.czm.api.dto.NotificationGetDTO;
import cz.cvut.fel.czm.api.dto.NotificationPostDTO;
import cz.cvut.fel.czm.model.notification.Notification;
import java.time.LocalDateTime;
import javax.annotation.processing.Generated;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2023-08-30T15:34:27+0200",
    comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.2 (Oracle Corporation)"
)
@Component
public class NotificationMapperImpl implements NotificationMapper {

...
}

这是实际的映射器:

import cz.cvut.fel.czm.api.dto.NotificationGetDTO;
import cz.cvut.fel.czm.api.dto.NotificationPostDTO;
import cz.cvut.fel.czm.model.notification.Notification;
import org.mapstruct.Mapper;

import java.time.LocalDateTime;

@Mapper(componentModel = "spring", imports = {LocalDateTime.class})
public interface NotificationMapper {
    NotificationGetDTO toDTO(Notification notification);

    Notification toModel(NotificationPostDTO notificationPostDTO);
}

我正在为该服务使用自定义父级,因此我不负责更改依赖项的版本。但父文件中的某个地方也可能存在错误。

这是我对 pom 的映射结构依赖:

        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
        </dependency>

这是我正在使用的 Maven 插件配置:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${org.projectlombok.lombok.version}</version>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>-Amapstruct.defaultComponentModel=spring</compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>

我检查了一下,我们使用的mapstruct版本是1.5.5final。

看起来,当我在本地运行服务时,端点可用并且正在工作,当我通过 Insomnia 访问它们时,但是当我在 InteliJIDEA 中打开它时,我遇到了 “javax.management.InstanceNotFoundException:orh.springframework.boot:类型=端点,名称=映射,*” 留言。

我尝试对mapstruct依赖项的版本进行硬编码,但这似乎不是问题的原因。 我还研究了哪些其他依赖项可能导致 javax 依赖项,但我找不到罪魁祸首。

换句话说,一切正常,但如果这个小事情在以后的生产中造成任何问题,我会很讨厌。我检查了已经迁移的其他服务,我认为其中没有一个发生过这种情况。

感谢您的任何建议。

java spring-boot intellij-idea microservices mapstruct
1个回答
0
投票

所以,我发现这根本不是一个基于代码的问题。 仍然不太确定为什么会发生这种情况,但我卸载了 IDE 并安装了新版本的 IntellijIDEA。现在一切正常。

谢谢大家的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.