1.服务端配置
引入pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
创建一个application.yml
server:
port: 8761
eureka:
instance:
statusPageUrlPath: ${management.context-path}/info
healthCheckUrlPath: ${management.context-path}/health
启动项目
@SpringBootApplication
@EnableEurekaServer
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
2. 客户端的配置
pom.xml的配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
创建一个application.properties
spring.mail.default-encoding=UTF-8
spring.mail.host= smtp.126.com
spring.mail.password= lgw1993
spring.mail.port= 25
spring.mail.protocol=smtp
spring.mail.username= lgw_999
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
spring.application.name=EMAIL_02
server.port=8082
发送邮件
@RestController
public class MailController {
@Autowired
private JavaMailSender sender;
@GetMapping("/send")
public String send(){
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("lgw_999@126.com");
message.setTo("1091835363@qq.com");
message.setSubject("这是一份测试邮件");
message.setText("请点击注册");
sender.send(message);
return "1";
}
}
启动项目
@SpringBootApplication
@EnableEurekaClient
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}