当前位置: 首页 > news >正文

宁波外贸网站做网站链接

宁波外贸网站,做网站链接,1.1做网站的目的,网站外链是什么目录 1.引入相关的依赖 2.nacos的yaml的相关配置&#xff0c;配置密码和相关算法 3.配置数据源连接 3.1 数据库连接配置 4.连接数据库配置类详解&#xff08;DataSourceConfig&#xff09;。 5.完整的配置类代码如下 1.引入相关的依赖 <dependency><groupId>…

目录

1.引入相关的依赖

2.nacos的yaml的相关配置,配置密码和相关算法

3.配置数据源连接

        3.1 数据库连接配置

4.连接数据库配置类详解(DataSourceConfig)。

5.完整的配置类代码如下


1.引入相关的依赖

<dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>3.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.propertiesapplication.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?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&nullCatalogMeansCurrent=trueusername: 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("Root@123");String  deSTr  = stringEncryptor.decrypt("N8VBWG5nOHvy5efX3/mlPAmdBykE7iDZFl362LyeaPRXMbLT0PzEIlB/KDXrNYz6");System.out.println("enStr==="+enStr);System.out.println("deSTr==="+deSTr);*/}}

你们的点赞和赞赏,是我继续前进的动力,谢谢。

http://www.yayakq.cn/news/691723/

相关文章:

  • 电商网站里的水果图片怎么做的智慧团建的网址
  • 加强网站建设的通知googleseo排名公司
  • 广州seo建站怎么建设分销模式手机网站
  • 公司做网站需要什么内容股票网站模板
  • 做可动模型的网站怎样进入国外网站
  • 做网站需要了解的知识常见的c2c平台有
  • 二级域名分发网站源码wordpress使用教学
  • 深圳做网站佰达科技三十什么是网络营销中最容易出现问题的步骤
  • filetype doc 网站建设苗木企业网站源码
  • 建站及推广新手怎么开婚庆公司
  • 用php做的网站论文wordpress 链接失效
  • 莞城区做网站俄语免费网站制作
  • 做公司+网站建设前端微信小程序开发教程
  • html官方下载徐州seo外包
  • 网站建设视频教程。企业在线培训系统
  • 辽宁网站开发wordpress 完整备份
  • 怎么用织梦源代码做网站五金制品东莞网站建设技术支持
  • 网站不设置关键词描述高端企业网站公司
  • 卡密网站怎么做的win7网站服务器制作软件
  • 网站开发大概要多少钱dedecms做网站和thinkphp
  • 济南招考院网站泰州网站建设专业团队
  • 郑州建设高端网站大型网站 建设意义
  • 湖南网站seo公司怎么做网站开发
  • 专业做外贸的网站临安区做网站的公司
  • 郭仓镇做网站微信seo什么意思
  • 提交网站地图站长之家seo综合
  • 商城网站建设4262图怪兽在线制作
  • ssl 加密网站网站被黑了怎么恢复
  • 做公司网站利润108社区找工作
  • 万创网站建设上海有名的广告设计公司