笔记

SpringBoot注入静态属性或静态对象

springboot中注入对象很方便,但是如果类是个工具类,里面的静态方法,只能使用静态属性。这时候就要想办法让静态属性可以被注入。

重点有两点

  1. 让spring接管类,可以使用@Component、@Service等注解
  2. 使用setter或@PostConstruct,将属性注入

springboot整合jasypt加密数据库配置

项目中会遇到数据库名称和密码需要加密防止泄露的需求,因此引入了jasypt。下面的例子是将jasypt的加密密钥写在了配置文件中,为了安全,实际引用时,需要将配置放到服务器的启动命令中,避免在代码中暴露密钥

1.引入maven依赖jasypt-spring-boot-starter

1
2
3
4
5
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>

2.启动类添加注解@EnableEncryptableProperties

1
2
3
4
5
6
7
8
9
10
11
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableEncryptableProperties
public class AdminMain {

public static void main(String[] args) {
SpringApplication.run(AdminMain.class, args);
}
}

rust语言字符串笔记

每种语言都免不了和字符串打交道,rust也不例外。由于rust本身的一些特性,字符串的使用和其他语言有很大的不同。

ubuntu18.4 打开文件中文乱码问题解决

本次记录针对ubuntu英文版,打开带有中文字符的文件是,显示乱码问题。不是给ubuntu系统切换到中文版。切换系统语言参考https://blog.csdn.net/qq_36588424/article/details/109617096

检查语言环境

出现乱码的原因其实是字符集问题。首先使用locale查看当前语言环境。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# locale
LANG=en_US
LANGUAGE=
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=