spring-context-support是spring-context的補充,如下子包說明
1. cache
一、cache包下補充org.springframework.cache.Cache的不同實現,主要是補充了caffine ehcache
二、支持Jcache標准(JSR-107)
二、使用TransactionSynchronizationManager提供了事務支持
2. mail
新增對郵件支持,使用javax.mail
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
spring:
mail:
host: smtp.qq.com
username: me@qq.com
password: qq授權嗎
default-encoding: UTF-8
properties:
mail:
smtp:
auth: true
port: 587
starttls:
enable: true
required: true
@Autowired
private JavaMailSender javaMailSender;
public void sendAttachmentsMail(String to, String subject, String content, String filePath) {
MimeMessage message = mailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(content, true);
FileSystemResource file = new FileSystemResource(new File(filePath));
String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
helper.addAttachment(fileName, file);
javaMailSender.send(message);
} catch (MessagingException e) {
e.printStackTrace();
logger.error("發送郵件時發生異常!", e);
}
}
3. scheduling
spring定時任務初始化是,先重容器中查找TaskScheduler,如果沒有則查找ScheduledExecutorService,都沒有通過RegisterDefaultTaskSchedulerPostProcessor注冊默認執行器,
默認執行器的實現有兩種。
如果沒有指定執行器會使用一個單線程ScheduledExecutorService,所以盡量定義自己的執行器
commonj已經不建議使用了
quartz比spring的@Scheduled功能能加豐富,支持數據庫存儲,分布式任務,動態修改任務
使用quartz需要定義QuartzJobBean,JobDetail,Trigger還是比較麻煩,推薦使用xxljob,更好管理
4. ui
對FreeMaker的支持