I have this REST controller:
package com.company.rest;
@RestController
@RequestMapping("/v1/orders")
public class OrderController {
@Autowired
private OrderService orderService;
...
being the OrderService implementation:
package com.company.service.impl;
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private MessageService messageService;
...
and MessageService implementation:
package com.company.service.impl;
import org.springframework.mail.javamail.JavaMailSender;
@Service
public class MessageServiceImpl implements MessageService {
@Autowired
public JavaMailSender emailSender;
...
This works perfect in development environment, but I have this unit test for the OrderController (based on this tutorial):
package com.company.test;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AdminApplication.class)
@WebAppConfiguration
public class OrderTest {
private MockMvc mockMvc;
@Autowired
private OrderService orderService;
...
which results in:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.mail.javamail.JavaMailSender' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Why does this dependency is satisfied in production but not in test? What do I need to do to allow this unit test successfully inject (or mock) a JavaMailSender implementation?