Błąd wywołania testu - brak beana typu JavaMailSender

0

Witam,
Mam taki test:

@RunWith(SpringRunner.class)
@DataJpaTest
@SpringBootTest(classes = app.BankApplication.class)
public class BankAccountDAOTest {

    @Autowired
    private TestEntityManager entityManager;

    @Autowired
    private BankAccountDAO bankAccountDAO;

    @Test
    public void whenFindByName_thenReturnEmployee() {
//        // given
//        Employee alex = new Employee("alex");
//        entityManager.persist(alex);
//        entityManager.flush();
//
//        // when
//        Employee found = employeeRepository.findByName(alex.getName());
//
//        // then
//        assertThat(found.getName())
//                .isEqualTo(alex.getName());
    }

}

W momencie wywołania wyrzuca błędy:

java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminController': Unsatisfied dependency expressed through field 'adminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminService': Unsatisfied dependency expressed through field 'mailService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mailService' defined in file [Bank\target\classes\service\MailService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is 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: {}	

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminService': Unsatisfied dependency expressed through field 'mailService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mailService' defined in file [Bank\target\classes\service\MailService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is 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: {}

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mailService' defined in file [Bank\target\classes\service\MailService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is 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: {}	

Caused by: 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: {}

Klasa Mail Service wygląda tak:

@Service
public class MailService {

    private JavaMailSender javaMailSender;

    @Autowired
    public MailService(JavaMailSender javaMailSender) {
        this.javaMailSender = javaMailSender;
    }

}

AdminController:

@Controller
@RequestMapping("/bank")
public class AdminController {

    @Autowired
    private AdminService adminService;

}

AdminService:

@Service
public class AdminService {

    @Autowired
    private MailService mailService;

}

Proszę o pomoc - patrzyłem np. tutaj https://stackoverflow.com/questions/23246912/could-not-autowire-org-springframework-mail-javamail-javamailsender ale ustawienia maila mam zapisane prawidłowo w pliku properties.

0

Magii tutaj nie ma. Jak nie dodasz do contextu beana JavaMailSender to nie ruszy... Tutaj masz podstawowy tutorial do Spring Mail http://www.baeldung.com/spring-email

1 użytkowników online, w tym zalogowanych: 0, gości: 1