0%

Spring Boot集成Artemis

什么是Artemis?

Artemis是神啊

Artemis是一个JMS产品。

准备工作

下载并安装ARTEMIS,在项目根目录创建存储数据的目录文件,并启动Artemis服务器。

Read more »

以QQ邮箱为例:使用Spring Boot发送Mail

准备工作

在QQ邮箱设置里开启SMTP服务,并获得授权码,记住授权码备用。

创建Spring Boot项目

通过Spring Initializr创建Spring Boot项目,依赖项包括spring-boot-starter-artemisspring-boot-starter-mail

Read more »

前因后果

微博图床加了防盗链,有一个缓兵之计是给所有<img>标签加上一个属性:referrerpolicy="no-referrer"

博客里插入了非常多图片,手动添加是不可能的,我们来用java批处理:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package sample;

import java.io.*;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MarkDownModify {
private final static Pattern PATTERN = Pattern.compile("(.*?)(<img.+>)(.*?)");

public static void addReferrerPolicy(File directory) throws IOException {
for (File file : Objects.requireNonNull(directory.listFiles())) {
modify(file);
}
}

private static void modify(File file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
line = regex(line);
content.append(line).append("\n");
}
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(content.toString());
writer.flush();
}

private static String regex(String line) {
Matcher matcher = PATTERN.matcher(line);
if (matcher.matches()) {
String s1 = matcher.group(1);
String s2 = matcher.group(2);
String s3 = matcher.group(3);
s2 = "<img " + "referrerpolicy=\"no-referrer\" " + s2.substring(5);
return s1 + s2 + s3;
} else {
return line;
}
}
}

图形界面

我用javaFX给这段批处理程序写了一个图形界面:

先选择md文件所在的目录,之后点击Execute按钮执行批处理,点击help查看帮助。

源码已经上传到了github:

https://github.com/carpediemtal/weibo-image-bed/tree/master

参考资料

如何在IDEA里运行javafx:

https://openjfx.io/openjfx-docs/

前因

博客里经常需要插入一些图片,在我最开始写博客的时候,和大多数人一样,我的博客部署在github上,首先接触到的是微博图床。

新浪微博的稳定性不必多说,加上Chrome微博图床插件更是妙不可言。

最开始的那会儿微博对我这种白嫖行为没什么限制,到后来,因为觉得github访问速度慢,于是想把博客迁移到自己的服务器上。迁移成功之后,却发现所有图片都不能正常访问了。究其原因,原来是微博加上了某种限制措施。

值得一提的是,如果博客部署在github或者gitee上,通过新浪微博生成的图片外链仍然可以正常访问,大概是因为github和gitee在微博的白名单里。

最后,我把博客迁移到了gitee上。gitee相比于github的优势主要在于访问速度,美中不足的是普通用户需要手动去更新仓库内容。

现在,我又觉得不过瘾,部署在github pages或者gitee pages的博客是很难被搜索引擎搜索到的(尤其是百度),还是想把博客部署在自己的服务器。

无意中了解到Github也可以当做图床来使用,于是我做了一番尝试,发现github的资源保存在亚马逊s3上,而访问亚马逊s3需要科学上网,我又把注意力放在了国产github之gitee上。

gitee也可以当做图床来用,现在最大的问题是:如何将我之前所有博客中微博图床的图片链接替换成gitee的链接呢?

  • 手动替换 ×
  • 用java √
Read more »

常用Maven依赖项

Java版本和UTF-8编码

1
2
3
4
5
6
7
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.ouputEncoding>UTF-8</project.reporting.ouputEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<java.version>14</java.version>
</properties>
Read more »