SpringBootApp上缺少TraceInputStream

时间:2018-03-27 07:41:36

标签: java spring-boot javamail

的pom.xml

exports.handler = (event, context, callback) => {
    // TODO implement


var AWS = require('aws-sdk');
var cloudwatch = new AWS.CloudWatch();
var params = {
              MetricName: 'EstimatedCharges',
              Namespace: 'AWS/Billing',
            };
            cloudwatch.listMetrics(params, function(err, data) {
              if (err) console.log(err, err.stack); // an error occurred
              else     console.log("success",JSON.stringify(data));           // successful response
            });

callback(null, 'Hello from Lambda');
};

EmailService

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.5.3</version>
 </dependency>

@Service public class EmailService { @Autowired private JavaMailSender sender; public void send() throws MessagingException { MimeMessage message = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message); helper.setText("Test body"); helper.setSubject("Test subject"); helper.setTo("mail@gmail.com"); sender.send(message); } } 里面,我得到了两个:

target/project/WEB-INF/libjavax.mail-1.5.3.jar, 但我得到了

  

java.lang.NoSuchMethodError:   com.sun.mail.util.TraceInputStream。(Ljava / IO / InputStream的; LCOM /太阳/邮件/ util的/ MailLogger;)V

编辑: 我已使用spring-boot-starter-mail-2.0.0.RELEASE.jar进行了检查,因此排除旧版dependency:tree所需的其他依赖项很少。我现在唯一与邮件相关的依赖项是mailapi,其中包含spring-boot-starter-mail,但问题仍然存在。

2 个答案:

答案 0 :(得分:0)

您的问题似乎与classpath中缺少的jar有关。要确保加载TraceInputStream,请尝试在任何类方法和调试中添加以下代码:

URL path = this.getClass().getResource("com.sun.mail.util.TraceInputStream");
System.out.println(path.getFile());

希望这会有所帮助:)

答案 1 :(得分:0)

错误为NoSuchMethodError,而非ClassNotFoundException

请检查

的输出
System.out.println(
   TraceInputStream.class.getProtectionDomain().getCodeSource().getLocation());

它可能主要指向旧版本的库。