spring-boot - Spring Boot 中带有 Gradle 的 Mapstruct + Lombok(未找到 Bean)

标签 spring-boot gradle intellij-idea lombok mapstruct

我正在尝试在 IntelliJ 的 spring boot 项目中将 mapstruct 与 gradle 结合使用。 它因任何原因不工作。

这是我的build.gradle

plugins {
    id 'org.springframework.boot' version '2.3.1.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_14

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    mavenLocal()

}

ext {
    mapstructVersion = "1.4.0.Beta2"
    lombokVersion = "1.18.12"
}

dependencies {
    compileOnly "org.mapstruct:mapstruct:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}"
    annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}"
    runtimeOnly'com.h2database:h2'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    compile 'com.h2database:h2:1.4.200'
}

test {
    useJUnitPlatform()
}

我试过这个链接:https://github.com/mapstruct/mapstruct-examples/blob/master/mapstruct-lombok/build.gradle

来自 mapstruct-examples 正如您可能注意到的那样,我只是采用了他们示例中的内容,但它不起作用。 我也在 IntelliJ 中启用了 AnnotationProcessor。不工作。 我还检查了 intellij 是否正在使用 gradle 构建和运行,它确实如此。 将不胜感激任何类型的回应。 提前致谢。

我在尝试运行我的应用程序时遇到的错误*

/Users/fazli/.sdkman/candidates/java/14.0.0.hs-adpt/bin/java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50802:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Volumes/Fazli SSD/MapStructExample/build/classes/java/main:/Volumes/Fazli SSD/MapStructExample/build/resources/main:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-data-jpa/2.3.1.RELEASE/5531a4cbd506f13a0b4483ed73c2e75a03d8da46/spring-boot-starter-data-jpa-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-validation/2.3.1.RELEASE/ec99ba85f02b2bec42b84c9c5e74d035ec61109a/spring-boot-starter-validation-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-web/2.3.1.RELEASE/555c4f90141cdbc7637145e413bca0d622ba6796/spring-boot-starter-web-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.h2database/h2/1.4.200/f7533fe7cb8e99c87a43d325a77b4b678ad9031a/h2-1.4.200.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.mapstruct/mapstruct/1.4.0.Beta2/4f45905f99bc1edea5910ad7215306cb6338a4bd/mapstruct-1.4.0.Beta2.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.18.12/48e4e5d60309ebd833bc528dcf77668eab3cd72c/lombok-1.18.12.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-aop/2.3.1.RELEASE/f42e23091d29bde8d1356e45cf13ad32dae51437/spring-boot-starter-aop-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-jdbc/2.3.1.RELEASE/800b64e76588ea88761ad9108cde762204805d66/spring-boot-starter-jdbc-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/jakarta.transaction/jakarta.transaction-api/1.3.3/c4179d48720a1e87202115fbed6089bdc4195405/jakarta.transaction-api-1.3.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/jakarta.persistence/jakarta.persistence-api/2.2.3/8f6ea5daedc614f07a3654a455660145286f024e/jakarta.persistence-api-2.2.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-core/5.4.17.Final/3b90ecf6fe93a27a27de9671c9fb25d03ba3def7/hibernate-core-5.4.17.Final.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.data/spring-data-jpa/2.3.1.RELEASE/1b5e106add569913f0c776aca62f85d8e9ca8cee/spring-data-jpa-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aspects/5.2.7.RELEASE/eb48f4ae3e1525179e1ccd10c0e09cfe5c27b8bb/spring-aspects-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter/2.3.1.RELEASE/e0d28696fea064578cb01da346232284f922eba4/spring-boot-starter-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.glassfish/jakarta.el/3.0.3/dab46ee1ee23f7197c13d7c40fce14817c9017df/jakarta.el-3.0.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.hibernate.validator/hibernate-validator/6.1.5.Final/e5539b4b05c1520a9b4c0a120fd6e4984a8d5dc8/hibernate-validator-6.1.5.Final.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-json/2.3.1.RELEASE/8342003919c7e5a2470072595ea190cb8a9552c0/spring-boot-starter-json-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-tomcat/2.3.1.RELEASE/5b599d0da04e724479c22daa47f9bfd62533a2e9/spring-boot-starter-tomcat-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-webmvc/5.2.7.RELEASE/dcd97bcb0a2aa33f272b0031e4771134e327d942/spring-webmvc-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-web/5.2.7.RELEASE/50a27c77e1731f3b7af5c2ae7caf6fe59bcc309/spring-web-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aop/5.2.7.RELEASE/9cf69f8e888091684c05f0a287bb638502e90725/spring-aop-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.aspectj/aspectjweaver/1.9.5/1740dc9140103b796d1722668805fd4cf852780c/aspectjweaver-1.9.5.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/5.2.7.RELEASE/847d31c90479a34e4e1fe7eeeb47ac89adce3438/spring-jdbc-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.zaxxer/HikariCP/3.4.5/aa1a2c00aae8e4ba8308e19940711bb9525b103d/HikariCP-3.4.5.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/antlr/antlr/2.7.7/83cd2cd674a217ade95a4bb83a8a14f351f48bd0/antlr-2.7.7.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy/1.10.11/16ac7e0d4afef10ac30db377e8151aff66a90e1c/byte-buddy-1.10.11.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml/classmate/1.5.1/3fe0bed568c62df5e89f4f174c101eab25345b6c/classmate-1.5.1.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.glassfish.jaxb/jaxb-runtime/2.3.3/c46b68a6e3a2d84ba4eb14c6a8a1a9a7be4048bc/jaxb-runtime-2.3.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.hibernate.common/hibernate-commons-annotations/5.1.0.Final/700aeedc4a2089816621948f0379e17cbd17d5db/hibernate-commons-annotations-5.1.0.Final.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.jboss.logging/jboss-logging/3.4.1.Final/40fd4d696c55793e996d1ff3c475833f836c2498/jboss-logging-3.4.1.Final.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.24.0-GA/d7466fc2e3af7c023e95c510f06448ad29b225b3/javassist-3.24.0-GA.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.jboss/jandex/2.1.3.Final/cd56603e39eb1421560b71daa584348ecfd9e0b8/jandex-2.1.3.Final.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.dom4j/dom4j/2.1.3/a75914155a9f5808963170ec20653668a2ffd2fd/dom4j-2.1.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.data/spring-data-commons/2.3.1.RELEASE/5ae66c24c223315d5b31a45590d293e9145c18e9/spring-data-commons-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/5.2.7.RELEASE/7fd9c4ea311a5d9ab92770be7fc93cc53db334f9/spring-context-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/5.2.7.RELEASE/32a76d825d8782ff278abe124ded9620444b4a74/spring-orm-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/5.2.7.RELEASE/66faebf0da41c67b67d082efc98e92c40e83e6b/spring-tx-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.2.7.RELEASE/5465ab17688ed62254fdef411cf883fd5c3b77a/spring-beans-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.7.RELEASE/56e14a3a5e2813534b5db2da1502cd58ab5bc61d/spring-core-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.30/b5a4b6d16ab13e34a88fae84c35cd5d68cac922c/slf4j-api-1.7.30.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.3.1.RELEASE/6d679d6ba26235a0e81ca1d58f9c1024d9427411/spring-boot-autoconfigure-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.3.1.RELEASE/ce8d8b6838ecceb68962b975b18682f4237ccf71/spring-boot-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-logging/2.3.1.RELEASE/3f242a91ffddf7485fde1367e1354c7e13024c8/spring-boot-starter-logging-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/jakarta.annotation/jakarta.annotation-api/1.3.5/59eb84ee0d616332ff44aba065f3888cf002cd2d/jakarta.annotation-api-1.3.5.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.26/a78a8747147d2c5807683e76ec2b633e95c14fe9/snakeyaml-1.26.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/jakarta.validation/jakarta.validation-api/2.0.2/5eacc6522521f7eacb081f95cee1e231648461e7/jakarta.validation-api-2.0.2.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.11.0/168b2d0e11478b9f0a1bfccd62d6b5e8547b1e6f/jackson-datatype-jsr310-2.11.0.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.11.0/cca91d6375258fd7ff2a6abb7bf91eef492bd606/jackson-datatype-jdk8-2.11.0.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.module/jackson-module-parameter-names/2.11.0/950a1e9a7c1093e7ffd92b216d5a0667f1e39058/jackson-module-parameter-names-2.11.0.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.11.0/8f5aaf3878b0647ff3a16610af53b1a5c05d9f15/jackson-databind-2.11.0.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-websocket/9.0.36/33fa5038aa66be6e9cc188000c2188aa4dd33c85/tomcat-embed-websocket-9.0.36.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/9.0.36/cf6574dd9c4764e60c548b69da52fc07a5a0a9bd/tomcat-embed-core-9.0.36.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/5.2.7.RELEASE/c98d7b10f959f9bedfbbbd4d723cf7a1f17a1f71/spring-expression-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.glassfish.jaxb/txw2/2.3.3/12f70b0ea4fc1ad45315e842f63f7c9a46f46530/txw2-2.3.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/jakarta.xml.bind/jakarta.xml.bind-api/2.3.3/48e3b9cfc10752fba3521d6511f4165bea951801/jakarta.xml.bind-api-2.3.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.sun.istack/istack-commons-runtime/3.0.11/4293b5f4e4e89d598f62bb2ba73b32132e7c3a27/istack-commons-runtime-3.0.11.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.2.7.RELEASE/72282e1f89c58284632220437b5a1e8066c53d7d/spring-jcl-5.2.7.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-to-slf4j/2.13.3/966f6fd1af4959d6b12bfa880121d4a2b164f857/log4j-to-slf4j-2.13.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.slf4j/jul-to-slf4j/1.7.30/d58bebff8cbf70ff52b59208586095f467656c30/jul-to-slf4j-1.7.30.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.11.0/c626020ae55d19c690d25cb51c1532ba76e5890f/jackson-annotations-2.11.0.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.11.0/f84302e14648f9f63c0c73951054aeb2ff0b810a/jackson-core-2.11.0.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.13.3/ec1508160b93d274b1add34419b897bae84c6ca9/log4j-api-2.13.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-core/1.2.3/864344400c3d4d92dfeb0a305dc87d953677c03c/logback-core-1.2.3.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-devtools/2.3.1.RELEASE/8f976b7b525d0f0b9c175c2fa5dfe9a07aa48503/spring-boot-devtools-2.3.1.RELEASE.jar:/Users/fazli/.gradle/caches/modules-2/files-2.1/com.sun.activation/jakarta.activation/1.2.2/74548703f9851017ce2f556066659438019e7eb5/jakarta.activation-1.2.2.jar com.example.mapstructexample.MapstructExampleApplication
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2020-07-16 19:50:22.678  INFO 1742 --- [  restartedMain] c.e.m.MapstructExampleApplication        : Starting MapstructExampleApplication on Fazli.local with PID 1742 (/Volumes/Fazli SSD/MapStructExample/build/classes/java/main started by fazli in /Volumes/Fazli SSD/MapStructExample)
2020-07-16 19:50:22.682  INFO 1742 --- [  restartedMain] c.e.m.MapstructExampleApplication        : No active profile set, falling back to default profiles: default
2020-07-16 19:50:22.796  INFO 1742 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-07-16 19:50:22.796  INFO 1742 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-07-16 19:50:24.915  INFO 1742 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-07-16 19:50:25.108  INFO 1742 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 147ms. Found 1 JPA repository interfaces.
2020-07-16 19:50:26.148  INFO 1742 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-07-16 19:50:26.168  INFO 1742 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-07-16 19:50:26.168  INFO 1742 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.36]
2020-07-16 19:50:26.345  INFO 1742 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-07-16 19:50:26.345  INFO 1742 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3549 ms
2020-07-16 19:50:26.403  INFO 1742 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-07-16 19:50:26.695  INFO 1742 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-07-16 19:50:26.709  INFO 1742 --- [  restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:d235bfcc-0a66-46db-9c77-2ec3093f7774'
2020-07-16 19:50:26.941  INFO 1742 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-07-16 19:50:27.070  INFO 1742 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-07-16 19:50:27.078  WARN 1742 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personController' defined in file [/Volumes/Fazli SSD/MapStructExample/build/classes/java/main/com/example/mapstructexample/web/controller/PersonController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.mapstructexample.web.mappers.PersonMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2020-07-16 19:50:27.078  INFO 1742 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-07-16 19:50:27.222  INFO 1742 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.17.Final
2020-07-16 19:50:27.597  INFO 1742 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-07-16 19:50:27.884  INFO 1742 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-07-16 19:50:29.320  INFO 1742 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-07-16 19:50:29.340  INFO 1742 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-07-16 19:50:29.341  INFO 1742 --- [  restartedMain] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Exception in thread "task-2" org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'springApplicationAdminRegistrar': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:212)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:245)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:197)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:134)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:99)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.access$100(DataSourceInitializedPublisher.java:50)
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher$DataSourceSchemaCreatedPublisher.lambda$postProcessEntityManagerFactory$0(DataSourceInitializedPublisher.java:200)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
2020-07-16 19:50:29.356  INFO 1742 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-07-16 19:50:29.590  WARN 1742 --- [  restartedMain] o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-200]
2020-07-16 19:50:29.592  INFO 1742 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2020-07-16 19:50:29.597  INFO 1742 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-07-16 19:50:29.600  INFO 1742 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-07-16 19:50:29.627  INFO 1742 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-07-16 19:50:29.977 ERROR 1742 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in com.example.mapstructexample.web.controller.PersonController required a bean of type 'com.example.mapstructexample.web.mappers.PersonMapper' that could not be found.


Action:

Consider defining a bean of type 'com.example.mapstructexample.web.mappers.PersonMapper' in your configuration.


Process finished with exit code 0


@Mapper(uses = {DateMapper.class})
@DecoratedWith(PersonAgeMapper.class)
public interface PersonMapper {

    PersonDto toPersonDto(Person person);

    Person toPerson(PersonDto dto);

}

最佳答案

您需要将映射器更新为:

@Mapper(uses = {DateMapper.class}, componentModel = "spring")
@DecoratedWith(PersonAgeMapper.class)
public interface PersonMapper {

    PersonDto toPersonDto(Person person);

    Person toPerson(PersonDto dto);

}

这将告诉 mapstruct 您正在使用 Spring Boot 来控制 bean 的实例化和 Autowiring 方式。

更多在mapstruct官方文档中:https://mapstruct.org/documentation/stable/reference/html/#configuration-options

备选方案 2: 我在我的 build.gradle 上添加了它,它在不使用的情况下工作:componentModel = "spring"

compileJava {
    options.compilerArgs = [
            '-Amapstruct.defaultComponentModel=spring'
    ]
}

关于spring-boot - Spring Boot 中带有 Gradle 的 Mapstruct + Lombok(未找到 Bean),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62940620/

相关文章:

gradle - Gradle文件重命名导致循环依赖项错误-为什么?

spring - @Cacheable注解的value和cacheName参数的区别

java - 使用 Spring Security 的多个用户

android - 在 IntelliJ IDEA 中找不到 "Sync Project with Gradle Files"按钮

gradle - 如何使用包含 filesMatching 的 copySpec 使用 Gradle 构建 war 文件

java - 我无法导入 Maven 项目选项

java - Reactor Core - Mono - onError Flatmap

java - Spring Boot无法在Docker环境中与MySQL DB通信

java - 在结构搜索中使用引用时,如何过滤其字段?

java - JSP页面只显示文件路径