Could not autowire org.springframework.mail.javamail.JavaMailSender

前端 未结 8 780
时光取名叫无心
时光取名叫无心 2021-02-11 22:18

I got the following problem when trying to run my application. Have debugged everything and still nothing.

The IDE is finding the bean without any issue so I\'m very con

8条回答
  •  梦毁少年i
    2021-02-11 23:06

    As per comment from mserioli the answer is that the bean must be declared in the configuration file being called at root.

    In this case: Move

    @Bean
        public JavaMailSenderImpl mailSender() 
    

    to

    public class ExtraConfig {
    @Bean
        public JavaMailSenderImpl mailSender() {
            JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
    
            javaMailSender.setProtocol("SMTP");
            javaMailSender.setHost("127.0.0.1");
            javaMailSender.setPort(25);
    
            return javaMailSender;
        }
    }
    

    which is called in:

    @Override
        protected Class[] getRootConfigClasses() {
            return new Class[]{ExtraConfig.class};
        }
    

    Thus solving the problem. Thanks guys for assistance.

提交回复
热议问题