使用java的spring-boot-starter-mail模块实现发送邮件功能

使用java的spring-boot-starter-mail模块实现发送邮件功能

一、注入配置

在application.properties文件中,新增

spring.mail.host=smtp.qq.com
spring.mail.port=587
spring.mail.username=xx@qq.com
spring.mail.password=xxx   //授权码
spring.mail.protocol=smtp
spring.mail.default-encoding=utf-8

注意如果出现以下报错,表示配置注入有问题,需要检查application.properties文件。

Field javaMailSender in com.jd.ci.service.impl.DailyServiceImpl required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
The injection point has the following annotations:-@org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.mail.javamail.JavaMailSender' in your configuration.

二、引入依赖

>在pom.xml文件中,新增依赖
<!-- email -->
<dependency>
    <groupId>org.springframework
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想了解如何集成使用javamelody-spring-boot-starter和druid-spring-boot-starter吗? 这两个starter都是用于在Spring Boot应用程序中进行监控和管理的。要使用它们,您需要将它们添加到应用程序的依赖项中。 首先,您需要在pom.xml文件中添加以下依赖项以使用javamelody-spring-boot-starter: ``` <dependency> <groupId>net.bull.javamelody</groupId> <artifactId>javamelody-spring-boot-starter</artifactId> <version>1.78.0</version> </dependency> ``` 接下来,您需要添加以下依赖项以使用druid-spring-boot-starter: ``` <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.20</version> </dependency> ``` 一旦您将这些依赖项添加到您的应用程序中,您需要在应用程序的配置文件中配置它们。例如,如果您使用的是application.properties,请添加以下属性来配置javamelody: ``` javamelody.enabled=true javamelody.storage-directory=monitoring ``` 对于druid,您需要添加以下属性: ``` spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.initialSize=5 spring.datasource.minIdle=5 spring.datasource.maxActive=20 spring.datasource.maxWait=60000 spring.datasource.filters=stat,wall spring.datasource.testWhileIdle=true spring.datasource.validationQuery=SELECT 1 FROM DUAL spring.datasource.testOnBorrow=false spring.datasource.testOnReturn=false spring.datasource.poolPreparedStatements=true spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 ``` 最后,您需要启动应用程序并访问http://localhost:8080/monitoring即可查看javamelody监控页面,而访问http://localhost:8080/druid即可查看druid监控页面。 希望这能帮助您集成使用javamelody-spring-boot-starter和druid-spring-boot-starter

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值