一. disconfclient的使用demo
https://github.com/Lin-lemon/disconf-demo
二. disconfweb
1. MailBean中配置的邮件不支持ssl,修改mailsender到配置文件中,给javaMailProperties赋值
<bean name="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${EMAIL_HOST}"/>
<property name="port" value="${EMAIL_PORT}"/>
<property name="username" value="${EMAIL_HOST_USER}"/>
<property name="password" value="${EMAIL_HOST_PASSWORD}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
</props>
</property>
</bean>
2.更新配置文件时,整个在一个事务中,包括发送邮件,由于开始时邮件配置有问题且没有超时时间,这里的事务一直无法提交,导致更新失败。
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
public String updateItemValue(Long configId, String value) {
Config config = getConfigById(configId);
String oldValue = config.getValue();
//
// 配置数据库的值 encode to db
//
configDao.updateValue(configId, CodeUtils.utf8ToUnicode(value));
configHistoryMgr.createOne(configId, oldValue, CodeUtils.utf8ToUnicode(value));
//
// 发送邮件通知
//
String toEmails = appMgr.getEmails(config.getAppId());
if (applicationPropertyConfig.isEmailMonitorOn()) {
boolean isSendSuccess = logMailBean.sendHtmlEmail(toEmails,
" config update", DiffUtils.getDiff(CodeUtils.unicodeToUtf8(oldValue),
value,
config.toString(),
getConfigUrlHtml(config)));
if (isSendSuccess) {
return "修改成功,邮件通知成功";
} else {
return "修改成功,邮件发送失败,请检查邮箱配置";
}
}
return "修改成功";
}
@Override
public String updateItemValue(Long configId, String value) {
Config config = getConfigById(configId);
String oldValue = config.getValue();
// 更新数据库中配置文件
updateItemValue(configId,value,oldValue);
//
// 发送邮件通知
//
String toEmails = appMgr.getEmails(config.getAppId());
if (applicationPropertyConfig.isEmailMonitorOn()) {
boolean isSendSuccess = logMailBean.sendHtmlEmail(toEmails,
" config update", DiffUtils.getDiff(CodeUtils.unicodeToUtf8(oldValue),
value,
config.toString(),
getConfigUrlHtml(config)));
if (isSendSuccess) {
return "修改成功,邮件通知成功";
} else {
return "修改成功,邮件发送失败,请检查邮箱配置";
}
}
return "修改成功";
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
private void updateItemValue(Long configId, String value, String oldValue) {
//
// 配置数据库的值 encode to db
//
configDao.updateValue(configId, CodeUtils.utf8ToUnicode(value));
configHistoryMgr.createOne(configId, oldValue, CodeUtils.utf8ToUnicode(value));
}