@Bean
    public JavaMailSender mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setDefaultEncoding("UTF-8");
        mailSender.setHost("smtp.googlemail.com");
        mailSender.setPort(465);
        mailSender.setUsername("[email protected]");
        mailSender.setPassword("XXXXXXXXXXXXXXX");
        Properties properties = new Properties();
        properties.put("mail.smtp.auth", true);
        properties.put("mail.smtp.starttls.enable", true);
        mailSender.setJavaMailProperties(properties);
        return mailSender;
    }

我正在尝试使用javamailsender发送邮件,因为我在获得“java.lang.NoClassDefFoundError: org/springframework/core/type/AnnotatedTypeMetadata”例外的任何建议后,使用注释配置了上面的代码。

最佳答案

似乎缺少spring-core依赖项。您应该添加此jar

10-06 00:38