男人和女人做羞羞的事情网站,共享办公都有哪些公司,wordpress底部自定义,wordpress 被墙目录
1.引入相关的依赖
2.nacos的yaml的相关配置#xff0c;配置密码和相关算法
3.配置数据源连接 3.1 数据库连接配置
4.连接数据库配置类详解#xff08;DataSourceConfig#xff09;。
5.完整的配置类代码如下 1.引入相关的依赖
dependencygroupId…目录
1.引入相关的依赖
2.nacos的yaml的相关配置配置密码和相关算法
3.配置数据源连接 3.1 数据库连接配置
4.连接数据库配置类详解DataSourceConfig。
5.完整的配置类代码如下 1.引入相关的依赖
dependencygroupIdcom.github.ulisesbocchio/groupIdartifactIdjasypt-spring-boot-starter/artifactIdversion3.0.3/version/dependency
2.nacos的yaml的相关配置配置密码和相关算法
jasypt:encryptor:algorithm: PBEWithHmacSHA512AndAES_256password: encryptionkey
3.配置数据源连接 3.1 数据库连接配置 使用ConfigurationProperties(prefix spring.datasource)注解的dataSource()方法通过DataSourceBuilder.create().build();创建了一个DataSource的bean。这个bean的配置信息来自于application.properties或application.yml文件中的spring.datasource前缀下的配置项比如数据库URL、用户名、密码等。 重点: 密码在yaml是加密的,如ENC(N8VBWG5nOHvy5efX3/mlPAmdBykE7iDZFl362LyeaPRXMbLT0PzEIlB/KDXrNYz6)配置了jasypt之后使用password作为密钥进行加密解密。
#加密
jasypt:encryptor:algorithm: PBEWithHmacSHA512AndAES_256password: encryptionkey
spring: datasource:driver-class-name: com.mysql.cj.jdbc.Driverjdbc-url: jdbc:mysql://localhost:3306/auth?serverTimezoneAsia/ShanghaiuseUnicodetruecharacterEncodingutf-8allowMultiQueriestruenullCatalogMeansCurrenttrueusername: rootpassword: ENC(N8VBWG5nOHvy5efX3/mlPAmdBykE7iDZFl362LyeaPRXMbLT0PzEIlB/KDXrNYz6)type: com.alibaba.druid.pool.DruidDataSourcedruid:initial-size: 5min-idle: 1max-active: 10max-wait: 60000validation-query: SELECT 1 FROM DUALtest-on-borrow: falsetest-on-return: falsetest-while-idle: truetime-between-eviction-runs-millis: 60000redis:port: 6379
mysql:driver: com.mysql.jdbc.driver
4.连接数据库配置类详解DataSourceConfig。 通过配置类的方式实现数据库的连接构建StringEncryptor 的bean对象实现密码的加密解密把加密解密串放到配置文件中用ENC()包裹着加载配置文件的时候有ENC()就会自动解密这样避免配置文件密码泄露的风险。 Beanpublic StringEncryptor stringEncryptor() {PooledPBEStringEncryptor encryptor new PooledPBEStringEncryptor();SimpleStringPBEConfig config new SimpleStringPBEConfig();config.setPassword(encryptionkey); // 加密密钥config.setAlgorithm(PBEWithHmacSHA512AndAES_256);config.setKeyObtentionIterations(1000);config.setPoolSize(1);config.setProviderName(SunJCE);config.setSaltGeneratorClassName(org.jasypt.salt.RandomSaltGenerator);config.setStringOutputType(base64);encryptor.setConfig(config);return encryptor;}
5.完整的配置类代码如下
package com.example.auth.config;import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.session.SqlSessionFactory;
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;import javax.annotation.PostConstruct;
import javax.sql.DataSource;/*** MybatisPlus配置类 数据库连接*/
Configuration
MapperScan(basePackages com.example.auth.mapper)
public class DataSourceConfig {Autowiredprivate StringEncryptor stringEncryptor;ConfigurationProperties(prefix spring.datasource)Beanpublic DataSource dataSource() {return DataSourceBuilder.create().build();}Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();//分页插件interceptor.addInnerInterceptor(new PaginationInnerInterceptor());//注册乐观锁插件interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());return interceptor;}Beanpublic SqlSessionFactory sqlSessionFactory(DataSource dataSource, MybatisPlusInterceptor interceptor) throws Exception {MybatisSqlSessionFactoryBean ssfb new MybatisSqlSessionFactoryBean();ssfb.setDataSource(dataSource);ssfb.setPlugins(interceptor);//到哪里找xml文件ssfb.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(classpath:/mapper/*Mapper.xml));return ssfb.getObject();}Beanpublic StringEncryptor stringEncryptor() {PooledPBEStringEncryptor encryptor new PooledPBEStringEncryptor();SimpleStringPBEConfig config new SimpleStringPBEConfig();config.setPassword(encryptionkey); // 加密密钥config.setAlgorithm(PBEWithHmacSHA512AndAES_256);config.setKeyObtentionIterations(1000);config.setPoolSize(1);config.setProviderName(SunJCE);config.setSaltGeneratorClassName(org.jasypt.salt.RandomSaltGenerator);config.setStringOutputType(base64);encryptor.setConfig(config);return encryptor;}PostConstructpublic void init(){/* String enStr stringEncryptor.encrypt(Root123);String deSTr stringEncryptor.decrypt(N8VBWG5nOHvy5efX3/mlPAmdBykE7iDZFl362LyeaPRXMbLT0PzEIlB/KDXrNYz6);System.out.println(enStrenStr);System.out.println(deSTrdeSTr);*/}}你们的点赞和赞赏是我继续前进的动力谢谢。