Ich versuche, Mapstruct zu verwenden, um Mapper in der Anwendung und Mapper im Detail zu generieren. Ich habe diesen Mapper im Anwendungsmodul
Wenn ich mvn package im übergeordneten POM ausführe, um alle Module zu erstellen, dann mvn spring-boot:run -pl application, wenn ich eine Anfrage sende und auf die Mapper-Methode klicke, wird dieser Fehler ausgegeben
Code: Select all
java.lang.Error: Unresolved compilation problems:
The import com.aura.app.http.rest.v1.institutions.requests cannot be resolved
The import com.aura.app.http.rest.v1.institutions.responses cannot be resolved
AppInstitutionMapper cannot be resolved to a type
CreateInstitutionRequestDTO cannot be resolved to a type
InstitutionResponseDTO cannot be resolved to a type
The method from(Institution) of type AppInstitutionMapperImpl must override or implement a supertype method
InstitutionResponseDTO cannot be resolved to a type
InstitutionResponseDTO cannot be resolved
at com.aura.app.http.rest.v1.institutions.mappers.AppInstitutionMapperImpl.(AppInstitutionMapperImpl.java:3) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483) ~[na:na]
at org.mapstruct.factory.Mappers.doGetMapper(Mappers.java:85) ~[mapstruct-1.6.3.jar:na]
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:69) ~[mapstruct-1.6.3.jar:na]
at org.mapstruct.factory.Mappers.getMapper(Mappers.java:58) ~[mapstruct-1.6.3.jar:na]
at com.aura.app.http.rest.v1.institutions.mappers.AppInstitutionMapper.(AppInstitutionMapper.java:11) ~[classes/:na]
at com.aura.app.http.rest.v1.institutions.InstitutionsController.createInstitution(InstitutionsController.java:51) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:565) ~[na:na]
Code: Select all
AppInstitutionMapper.javaCode: Select all
package com.aura.app.http.rest.v1.institutions.mappers;
import com.aura.app.http.rest.v1.institutions.requests.CreateInstitutionRequestDTO;
import com.aura.app.http.rest.v1.institutions.responses.InstitutionResponseDTO;
import com.aura.core.institutions.entities.Institution;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface AppInstitutionMapper {
AppInstitutionMapper INSTANCE = Mappers.getMapper(AppInstitutionMapper.class);
Institution from(CreateInstitutionRequestDTO dto);
InstitutionResponseDTO from(Institution institution);
}
Code: Select all
package com.aura.app.http.rest.v1.institutions.mappers;
import com.aura.app.http.rest.v1.institutions.requests.CreateInstitutionRequestDTO;
import com.aura.app.http.rest.v1.institutions.responses.InstitutionResponseDTO;
import com.aura.core.institutions.entities.Institution;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-11-07T00:04:30+0800",
comments = "version: 1.6.3, compiler: javac, environment: Java 25 (Homebrew)"
)
public class AppInstitutionMapperImpl implements AppInstitutionMapper {
@Override
public Institution from(CreateInstitutionRequestDTO dto) {
if ( dto == null ) {
return null;
}
Institution.InstitutionBuilder institution = Institution.builder();
institution.name( dto.getName() );
institution.email( dto.getEmail() );
institution.uen( dto.getUen() );
institution.address( dto.getAddress() );
institution.contactNumber( dto.getContactNumber() );
return institution.build();
}
@Override
public InstitutionResponseDTO from(Institution institution) {
if ( institution == null ) {
return null;
}
InstitutionResponseDTO.InstitutionResponseDTOBuilder institutionResponseDTO = InstitutionResponseDTO.builder();
institutionResponseDTO.id( institution.id() );
institutionResponseDTO.name( institution.name() );
institutionResponseDTO.email( institution.email() );
institutionResponseDTO.uen( institution.uen() );
institutionResponseDTO.address( institution.address() );
institutionResponseDTO.contactNumber( institution.contactNumber() );
return institutionResponseDTO.build();
}
}
In meinem übergeordneten POM liste ich meine Module wie folgt auf:
Code: Select all
4.0.0
com.aura
parent
1.0.0
pom
Aura Parent
Parent POM for Aura
core
details
application
24
24
24
UTF-8
3.5.6
1.18.38
1.6.3
0.2.0
26.0.7
6.6.5.Final
2.8.8
3.4.2
3.0.2
1.4.1
4.13.2
2.0.17
4.27.0
4.27.0
4.23.0
8.0.2.Final
42.7.5
org.springframework.boot
spring-boot-dependencies
${spring.boot.version}
pom
import
Code: Select all
4.0.0
com.aura
parent
1.0.0
jar
application
1.0.0
aura application containing app runtime and configurations
com.aura
core
1.0.0
com.aura
details
1.0.0
org.slf4j
slf4j-api
${slf4j.version}
org.liquibase
liquibase-core
${liquibase.version}
org.springframework.boot
spring-boot-starter-web
org.springdoc
springdoc-openapi-starter-webmvc-ui
${springdoc-openapi-stgarter-webmvc-ui.version}
org.keycloak
keycloak-admin-client
${keycloak-admin-client.version}
org.postgresql
postgresql
runtime
com.h2database
h2
org.springframework.boot
spring-boot-starter-validation
org.springframework.boot
spring-boot-devtools
runtime
true
org.mapstruct
mapstruct
${mapstruct.version}
org.projectlombok
lombok
${lombok.version}
provided
org.springframework.boot
spring-boot-starter-oauth2-resource-server
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-contract-shade
4.1.0
org.springframework.security
spring-security-test
test
generate-db-changelog
org.liquibase
liquibase-maven-plugin
${liquibase-maven-plugin.version}
src/main/resources/db/liquibase.properties
org.liquibase.ext
liquibase-hibernate6
${liquibase-hibernate6.version}
jakarta.validation
jakarta.validation-api
${jakarta-validation-api.version}
org.hibernate.validator
hibernate-validator
${hibernate-validation.version}
org.postgresql
postgresql
${postgresql.version}
report-api
org.apache.maven.plugins
maven-compiler-plugin
3.11.0
${java.version}
${java.version}
${java.version}
org.mapstruct
mapstruct-processor
${mapstruct.version}
org.projectlombok
lombok
${lombok.version}
org.projectlombok
lombok-mapstruct-binding
${lombok-mapstruct-binding.version}
org.springframework.boot
spring-boot-maven-plugin
${spring.boot.version}
com.aura.app.Application
JAR
org.projectlombok
lombok
com.aura
core
com.aura
details
exec
repackage
repackage
Weitere Details
Wenn ich in das JAR des Anwendungsmoduls schaue, um zu überprüfen, ob die relevanten Klassen vorhanden sind, stelle ich fest, dass alle Klassen vorhanden sind
Die Detailmodulabhängigkeit befindet sich im Klassenpfad als JAR
Code: Select all
jar tf application/target/report-api.jar | grep /details
> BOOT-INF/lib/details-1.0.0.jar
Code: Select all
jar tf application/target/report-api.jar | grep /mapper
> BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/mappers/
BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/mappers/AppInstitutionMapper.class
BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/mappers/AppInstitutionMapperImpl.class
BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/mappers/UserMapper.class
Code: Select all
jar tf application/target/report-api.jar | grep /response
BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/responses/
BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/responses/InstitutionResponseDTO$InstitutionResponseDTOBuilder.class
BOOT-INF/classes/com/aura/app/http/rest/v1/institutions/responses/InstitutionResponseDTO.class
Mobile version