Reputation: 614
I'm using one mapper generated with MapStruct:
@Mapper
public interface CustomerMapper {
Customer mapBankCustomerToCustomer(BankCustomerData bankCustomer);
}
The default component model is spring (set in pom.xml)
<compilerArg>-Amapstruct.defaultComponentModel=spring</compilerArg>
I have a service in which I inject the customer mapper and works fine when I run the application
@Autowired
private CustomerMapper customerMapper;
But when I run unit tests that involves @SpringBootTest
@SpringBootTest
@AutoConfigureMockMvc
@RunWith(SpringRunner.class)
public class SomeControllerTest {
@Mock
private SomeDependency someDependency;
@InjectMocks
private SomeController someController;
@Test
public void shouldDoSomething() {
...
}
}
I get an org.springframework.beans.factory.UnsatisfiedDependencyException
Unsatisfied dependency expressed through field 'customerMapper'
Upvotes: 5
Views: 11219
Reputation: 83
I followed this answer and my problem was solved as quickly as I pasted proposed lines in my build.gradle file
Upvotes: 1
Reputation: 21423
As you are running your tests via the IDE there are 2 possibilities:
To rule out the possibilities do the following for each:
@Mapper(componentModel = "spring")
. I personally prefer this option as you are IDE independent. You can also use a @MapperConfig
that you can applymapstruct.defaultComponentModel
as option name and spring
as value. I am not sure how to do it for EclipseUpvotes: 0