I have following test:
@SpringBootTest(classes = {SomeService.class, DtoMapperImpl.class})
class SomeServiceTest {
And following mapper:
@Mapper(componentModel = "spring")
public interface DtoMapper {
EntityDto toDto(Entity entity);
}
I'm not changing packages (this means DtoMapperImpl is in the same package as DtoMapper)
As soon as I change Impl to interface my test fails:
@SpringBootTest(classes = {SomeService.class, DtoMapper.class})
class SomeServiceTest {
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'someService': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'DtoMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Can you please advise best way solving this? I'm on MapStruct 1.3.1.Final
@SpringBootTestwrong. That is for spring boot integration tests, you want to test your service then don't use@SpringBootTestfor that. - M. Deinumclassespart) OR you write a simple unit test for your service and manually inject the mapper by obtaining it from MapStruct itself. - M. Deinum