亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes 出現這個異常是怎么回事呀

package?com.ep.email.hello;

import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.beans.factory.annotation.Value;
import?org.springframework.mail.SimpleMailMessage;
import?org.springframework.mail.javamail.JavaMailSender;
import?org.springframework.stereotype.Service;

@Service
public?class?MailService?{

????@Value("${spring.mail.username}")
????private?String?from;

????@Autowired
????private?JavaMailSender?mailSender;

????public?void?sayHello(){
????????System.out.println("hello?springboot!");
????}

????public?void?sendSimpleMail(String?to,String?subject,String?content){

????????SimpleMailMessage?message=new?SimpleMailMessage();
????????message.setTo(to);
????????message.setSubject(subject);
????????message.setText(content);
????????message.setFrom(from);

????????mailSender.send(message);
????}

}


spring.mail.host=smtp.126.com
[email protected]
spring.mail.password=yourPassword126
spring.mail.default-encoding=UTF-8


pom.xml也配置了依賴mail

正在回答

4 回答

你這個配置文件是客戶端授權碼,不要用他的那個要用自己郵箱的授權碼

我是因為測試類里面郵箱后綴忘寫了


0 回復 有任何疑惑可以回復我~

我也遇到了,因為 spring-boot-mail 項目是我們之前helloWorld直接復制過來的,所以會有之前生成的HelloWorldApplication.class 文件

解決方法:把?spring-boot-mail 這個項目 clean 一下,然后再compile 一下,其他不做任何修改,在去執行測試代碼即可


0 回復 有任何疑惑可以回復我~

我也遇到了,怎么解決?

0 回復 有任何疑惑可以回復我~

from?? 字段應該是final的

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes 出現這個異常是怎么回事呀

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號