Код: Выделить всё
org.apache.maven.plugins
maven-compiler-plugin
${java.version}
${java.version}
org.mapstruct
mapstruct-processor
${mapstruct.version}
package com.example.demo;
import javax.annotation.processing.Generated;
import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2025-04-12T09:58:09+0000",
comments = "version: 1.6.3, compiler: javac, environment: Java 21.0.5"
)
@Component
public class MyMapperImpl implements MyMapper {
@Override...
< /code>
Однако при запуске приложения или даже запуска тестов при выполнении MVN Clean Install, я получаю ошибки следующих: < /p>
2025-04-12T09:58:45.338Z WARN 12073 --- [demo] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoController' defined in file [/workspaces/spring/mapstruct/target/classes/com/example/demo/DemoController.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'com.example.demo.MyMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2025-04-12T09:58:45.340Z INFO 12073 --- [demo] [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2025-04-12T09:58:45.346Z INFO 12073 --- [demo] [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-04-12T09:58:45.363Z ERROR 12073 --- [demo] [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.example.demo.DemoController required a bean of type 'com.example.demo.MyMapper' that could not be found.
Action:
Consider defining a bean of type 'com.example.demo.MyMapper' in your configuration.
< /code>
Итак, я почти уверен, что у меня есть фасоль типа com.example.demo.mymapperimpl, который реализует com.example.demo.mymapper? Кроме того, в своем фактическом приложении я добавил регистрацию трассировки для org.springframework.beans и мог подтвердить, что в ApplicationContext был боб MyMapPerimpl, но не может быть найдено боба типа MyMapper.
.
Подробнее здесь: https://stackoverflow.com/questions/795 ... ing-boot-3