Code: Select all
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userControllerImpl':
Unsatisfied dependency expressed through field 'userMapper': Error creating bean with name 'com.acneUserMapper':
Failed to instantiate [com.acne.user.UserMapper]: Specified class is an interface
< /code>
Test: < /p>
@WebMvcTest(UserController.class)
@Import(UserMapper.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@AutoConfigureWebMvc
public class UserControllerTests {
@Autowired
private MockMvc mockMvc;
@Test
public void shouldGetAuthenticatedUser() throws Exception {
this.mockMvc.perform(get("/api/users/me").with(oidcLogin())).andExpect(status().isOk());
}
}
< /code>
UsMapper: < /p>
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface UserMapper {
public UserResponseDTO toUserResponseDTO(UserEntity userEntity);
public UserDTO toDto(UserEntity entity);
public UserEntity toEntity(UserDTO dto);
}
< /code>
UserController & Impl: < /p>
public interface UserController {
@GetMapping("/me")
public ResponseEntity getCurrentUser(Authentication authentication);
}
< /code>
@RestController
public class UserControllerImpl implements UserController {
@Autowired
UserMapper userMapper;
@Autowired
UserService userService;
@Override
public ResponseEntity getCurrentUser(Authentication currentUser) {
UserEntity loggedUser = userService.findByLoginOrError(currentUser.getName());
return ResponseEntity.ok(userMapper.toUserResponseDTO(loggedUser));
}
}
Code: Select all
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.acne.user.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency a
nnotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}