Skip to content

Commit a6dfe7e

Browse files
java mail
1 parent f7f2eec commit a6dfe7e

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
<artifactId>druid</artifactId>
9393
<version>1.0.5</version>
9494
</dependency>
95+
<!--ehcache的依赖-->
96+
<dependency>
97+
<groupId>net.sf.ehcache</groupId>
98+
<artifactId>ehcache</artifactId>
99+
</dependency>
100+
<dependency>
101+
<!--java mail的依赖-->
102+
<groupId>org.springframework.boot</groupId>
103+
<artifactId>spring-boot-starter-mail</artifactId>
104+
</dependency>
95105
</dependencies>
96106

97107
<build>

src/main/java/com/controller/CacheController.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ public class CacheController {
1717
private CacheService cacheService;
1818

1919
@RequestMapping(value = "",method = RequestMethod.GET)
20-
public String getByCache(){
20+
public String getByCache() {
2121
long startTme = System.currentTimeMillis();
2222
long timeTme = this.cacheService.getByCache();
2323
long endTme = System.currentTimeMillis();
2424
System.out.println("耗时:" + (endTme - startTme));
2525
return timeTme + "";
2626
}
27+
28+
@RequestMapping(value = "",method = RequestMethod.POST)
29+
public void save(){
30+
this.cacheService.save();
31+
}
32+
33+
@RequestMapping(value = "",method = RequestMethod.DELETE)
34+
public void delete(){
35+
this.cacheService.delete();
36+
}
2737
}

src/main/resources/application.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ spring:
6363
host: localhost
6464
port: 5672
6565
username: guest
66-
password: guest
66+
password: guest
67+
mail:
68+
host: smpt.163.com
69+
username:
70+
password:
71+
port: 25
72+
protocol: smtp
73+
default-encoding: utf-8

src/main/resources/ehcache.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="ehcache.xsd">
4+
<cache name="ehcache"
5+
maxElementsInMemory="1000"
6+
timeToLiveSeconds="300">
7+
</cache>
8+
</ehcache>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.mail.SimpleMailMessage;
8+
import org.springframework.mail.javamail.JavaMailSenderImpl;
9+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10+
11+
/**
12+
* Created by zhuzhengping on 2017/3/16.
13+
*/
14+
@RunWith(SpringJUnit4ClassRunner.class)
15+
@SpringBootTest
16+
public class MailTest {
17+
18+
19+
@Autowired
20+
private JavaMailSenderImpl mailSender;
21+
22+
@Test
23+
public void send(){
24+
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
25+
simpleMailMessage.setTo(new String[]{"1111111111@qq.com"});
26+
simpleMailMessage.setFrom("zhu_zhengping@163.com");
27+
simpleMailMessage.setSubject("spring boot mail [text]");
28+
simpleMailMessage.setText(" this is an simple text ");
29+
30+
mailSender.send(simpleMailMessage);
31+
32+
System.out.println("mail has been send");
33+
}
34+
}

0 commit comments

Comments
 (0)