二、集成方法
官网上推荐的集成到SpringBoot项目中,有3种方法分别是:
- 如果使用@SpringBootApplication或@EnableAutoConfiguration,则仅需要添加jasypt-spring-boot-starter启动器jar到您的类路径中即可,它自动会在整个 Spring 环境中启用可加密属性。
- 添加jasypt-spring-boot到您的类路径并添加@EnableEncryptableProperties到您的主配置类以在整个 Spring 环境中启用可加密属性。
- 添加jasypt-spring-boot到您的类路径并使用@EncrytablePropertySource注解声明单独的可加密属性源。
2.1 方式一
在Springboot应用程序中,如果使用了@SpringBootApplication 或者@EnableAutoConfiguration注解,则可以在pom文件中添加jasypt-spring-boot-starter依赖,然后就可以在整个Spring环境中使用jasypt对属性进行加解密操作(属性包括:系统属性、环境属性、命令行参数、application.properties、application-*.properties、yml属性以及任何其他属性源)。
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<!-- JDK9+用3.x版本,JDK8用2.x版本 -->
<!-- 仓库:https://repo1.maven.org/maven2/com/github/ulisesbocchio/jasypt-spring-boot-starter/ -->
<version>2.1.2</version>
</dependency>
2.2 方式二
如果项目中没有使用到@SpringBootApplication 或者@EnableAutoConfiguration 自动配置注解,则可以通过以下两个步骤完成对Jasypt的集成。
步骤一:pom文件引入jasypt-spring-boot依赖
<dependency>
<groupId>com.github.ulise