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

网站服务费算什么费用app优化方案

网站服务费算什么费用,app优化方案,用dw6做网站首页,wordpress5.0改进公司要求redis配置密码使用密文,但是程序使用的是spring默认的redisTemplate,那么就需要修改配置实现密码加解密。 先搞个加密工具类: public class SM2Encryptor {// 加密,使用公钥public static String encryptText(String pub…

公司要求redis配置密码使用密文,但是程序使用的是spring默认的redisTemplate,那么就需要修改配置实现密码加解密。
先搞个加密工具类:

public class SM2Encryptor {// 加密,使用公钥public static String encryptText(String publicKey, String originalText) throws Exception {//...为null判断return Sm2.doEncrypt(originalText, publicKey);}//解密,使用私钥public static String decryptText(String privateKey, String cipherText) throws Exception {//...为null判断return Sm2.doDecrypt(cipherText, privateKey);}// 生成密钥对方法//...
}

1. Redis默认配置

最简单的使用其实开箱即可用,添加依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

本机启动redis,一切采用默认的配置 (host:127.0.0.1, port:6379, 无密码)

然后就可以直接注入redisTemplate实例,进行各种读写操作

@SpringBootApplication
public class Application {public Application(RedisTemplate<String, String> redisTemplate) {redisTemplate.opsForValue().set("hello", "world");String ans = redisTemplate.opsForValue().get("hello");Assert.isTrue("world".equals(ans));}public static void main(String[] args) {SpringApplication.run(Application.class, args);}
}

2. 自定义配置参数

前面是默认的配置参数,在实际的使用中,一般都会修改这些默认的配置项,如果我的应用中,只有一个redis,那么完全可以只修改默认的配置参数
修改配置文件: application.yml

spring:redis:host: 127.0.0.1port: 6379password:database: 0lettuce:pool:max-active: 32max-wait: 300msmax-idle: 16min-idle: 8

使用和前面没有什么区别,直接通过注入RedisTemplate来操作即可,需要额外注意的是设置了连接池的相关参数,需要额外引入依赖

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId>
</dependency>

3. 多redis配置

依赖多个不同的redis,也就是说我的项目需要从多个redis实例中获取数据,这种时候,就不能直接使用默认的,需要我们自己来声明ConnectionFactoryRedisTemplate

spring:redis:host: 127.0.0.1port: 6379password:lettuce:pool:max-active: 32max-wait: 300max-idle: 16min-idle: 8database: 0local-redis:host: 127.0.0.1port: 6379database: 0password:lettuce:pool:max-active: 16max-wait: 100max-idle: 8min-idle: 4

对应的配置类,采用Lettuce,基本设置如下,套路都差不多,先读取配置,初始化ConnectionFactory,然后创建RedisTemplate实例,设置连接工厂

@Configuration
public class RedisAutoConfig {@Beanpublic LettuceConnectionFactory defaultLettuceConnectionFactory(RedisStandaloneConfiguration defaultRedisConfig,GenericObjectPoolConfig defaultPoolConfig) {LettuceClientConfiguration clientConfig =LettucePoolingClientConfiguration.builder().commandTimeout(Duration.ofMillis(100)).poolConfig(defaultPoolConfig).build();return new LettuceConnectionFactory(defaultRedisConfig, clientConfig);}@Beanpublic RedisTemplate<String, String> defaultRedisTemplate(LettuceConnectionFactory defaultLettuceConnectionFactory) {RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(defaultLettuceConnectionFactory);redisTemplate.afterPropertiesSet();return redisTemplate;}@Bean@ConditionalOnBean(name = "localRedisConfig")public LettuceConnectionFactory localLettuceConnectionFactory(RedisStandaloneConfiguration localRedisConfig,GenericObjectPoolConfig localPoolConfig) {LettuceClientConfiguration clientConfig =LettucePoolingClientConfiguration.builder().commandTimeout(Duration.ofMillis(100)).poolConfig(localPoolConfig).build();return new LettuceConnectionFactory(localRedisConfig, clientConfig);}@Bean@ConditionalOnBean(name = "localLettuceConnectionFactory")public RedisTemplate<String, String> localRedisTemplate(LettuceConnectionFactory localLettuceConnectionFactory) {RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(localLettuceConnectionFactory);redisTemplate.afterPropertiesSet();return redisTemplate;}@Configuration@ConditionalOnProperty(name = "host", prefix = "spring.local-redis")public static class LocalRedisConfig {@Value("${spring.local-redis.host:127.0.0.1}")private String host;@Value("${spring.local-redis.port:6379}")private Integer port;@Value("${spring.local-redis.password:}")private String password;@Value("${spring.local-redis.database:0}")private Integer database;@Value("${spring.local-redis.lettuce.pool.max-active:8}")private Integer maxActive;@Value("${spring.local-redis.lettuce.pool.max-idle:8}")private Integer maxIdle;@Value("${spring.local-redis.lettuce.pool.max-wait:-1}")private Long maxWait;@Value("${spring.local-redis.lettuce.pool.min-idle:0}")private Integer minIdle;@Beanpublic GenericObjectPoolConfig localPoolConfig() {GenericObjectPoolConfig config = new GenericObjectPoolConfig();config.setMaxTotal(maxActive);config.setMaxIdle(maxIdle);config.setMinIdle(minIdle);config.setMaxWaitMillis(maxWait);return config;}@Beanpublic RedisStandaloneConfiguration localRedisConfig() {RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();config.setHostName(host);config.setPassword(RedisPassword.of(password));config.setPort(port);config.setDatabase(database);return config;}}@Configurationpublic static class DefaultRedisConfig {@Value("${spring.redis.host:127.0.0.1}")private String host;@Value("${spring.redis.port:6379}")private Integer port;@Value("${spring.redis.password:}")private String password;@Value("${spring.redis.database:0}")private Integer database;@Value("${spring.redis.lettuce.pool.max-active:8}")private Integer maxActive;@Value("${spring.redis.lettuce.pool.max-idle:8}")private Integer maxIdle;@Value("${spring.redis.lettuce.pool.max-wait:-1}")private Long maxWait;@Value("${spring.redis.lettuce.pool.min-idle:0}")private Integer minIdle;private static final String PRIVATEKEY = "4334f34t2t2t54ytw4erg3y245g45wt4qf4";@Beanpublic GenericObjectPoolConfig defaultPoolConfig() {GenericObjectPoolConfig config = new GenericObjectPoolConfig();config.setMaxTotal(maxActive);config.setMaxIdle(maxIdle);config.setMinIdle(minIdle);config.setMaxWaitMillis(maxWait);return config;}@Beanpublic RedisStandaloneConfiguration defaultRedisConfig() {RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();config.setHostName(host);// config.setPassword(RedisPassword.of(password));config.setPassword(SM2Encryptor.decryptText(PRIVATEKEY, password)); // 此处密文需要解密config.setPort(port);config.setDatabase(database);return config;}}
}

测试类如下,简单的演示下两个template的读写

@SpringBootApplication
public class Application {public Application(RedisTemplate<String, String> localRedisTemplate, RedisTemplate<String, String>defaultRedisTemplate)throws InterruptedException {// 10s的有效时间localRedisTemplate.delete("key");localRedisTemplate.opsForValue().set("key", "value", 100, TimeUnit.MILLISECONDS);String ans = localRedisTemplate.opsForValue().get("key");System.out.println("value".equals(ans));TimeUnit.MILLISECONDS.sleep(200);ans = localRedisTemplate.opsForValue().get("key");System.out.println("value".equals(ans) + " >> false ans should be null! ans=[" + ans + "]");defaultRedisTemplate.opsForValue().set("key", "value", 100, TimeUnit.MILLISECONDS);ans = defaultRedisTemplate.opsForValue().get("key");System.out.println(ans);}public static void main(String[] args) {SpringApplication.run(Application.class, args);}
}

重点:

  • 注意 localRedisTemplate, defaultRedisTemplate 两个对象不相同(看debug窗口后面的@xxx)
  • 同样两个RedisTemplate的ConnectionFactory也是两个不同的实例(即分别对应前面配置类中的两个Factory)
  • 执行后输出的结果正如我们预期的redis操作
    • 塞值,马上取出没问题
    • 失效后,再查询,返回null
  • 最后输出异常日志,提示如下
Description:
Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required a single bean, but 2 were found:- defaultLettuceConnectionFactory: defined by method 'defaultLettuceConnectionFactory' in class path resource [com/git/hui/boot/redis/config/RedisAutoConfig.class]- localLettuceConnectionFactory: defined by method 'localLettuceConnectionFactory' in class path resource [com/git/hui/boot/redis/config/RedisAutoConfig.class]Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

上面表示说有多个ConnectionFactory存在,然后创建默认的RedisTemplate就不知道该选择哪一个了,有两种方法解决:
方法一:指定默认的ConnectionFactory
借助@Primary来指定默认的连接工厂,然后在使用工程的时候,通过@Qualifier注解来显示指定,我需要的工厂是哪个(主要是localRedisTemplate这个bean的定义,如果不加,则会根据defaultLettuceConnectionFactory这个实例来创建Redis连接了)

@Bean
@Primary
public LettuceConnectionFactory defaultLettuceConnectionFactory(RedisStandaloneConfiguration defaultRedisConfig,GenericObjectPoolConfig defaultPoolConfig) {// ...
}@Bean
public RedisTemplate<String, String> defaultRedisTemplate(@Qualifier("defaultLettuceConnectionFactory") LettuceConnectionFactory defaultLettuceConnectionFactory) {// ....
}@Bean
@ConditionalOnBean(name = "localRedisConfig")
public LettuceConnectionFactory localLettuceConnectionFactory(RedisStandaloneConfiguration localRedisConfig,GenericObjectPoolConfig localPoolConfig) {// ...
}@Bean
@ConditionalOnBean(name = "localLettuceConnectionFactory")
public RedisTemplate<String, String> localRedisTemplate(@Qualifier("localLettuceConnectionFactory") LettuceConnectionFactory localLettuceConnectionFactory) {// ...
}

方法二:忽略默认的自动配置类
既然提示的是org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration类加载bean冲突,那么就不加载这个配置即可

@SpringBootApplication
@EnableAutoConfiguration(exclude = {RedisAutoConfiguration.class, RedisReactiveAutoConfiguration.class})
public class Application {// ...
}

文章转载自:
http://mastication.pwrb.cn
http://biscayne.pwrb.cn
http://newspaperdom.pwrb.cn
http://ask.pwrb.cn
http://seletron.pwrb.cn
http://congeries.pwrb.cn
http://exsection.pwrb.cn
http://fazenda.pwrb.cn
http://cong.pwrb.cn
http://caulomic.pwrb.cn
http://canalisation.pwrb.cn
http://luteous.pwrb.cn
http://antewar.pwrb.cn
http://ophthalmology.pwrb.cn
http://undefinable.pwrb.cn
http://bandbox.pwrb.cn
http://incongruent.pwrb.cn
http://embourgeoisement.pwrb.cn
http://trickily.pwrb.cn
http://darkadapted.pwrb.cn
http://dasyure.pwrb.cn
http://plaided.pwrb.cn
http://independently.pwrb.cn
http://corfam.pwrb.cn
http://legalist.pwrb.cn
http://ichnolite.pwrb.cn
http://singly.pwrb.cn
http://blissout.pwrb.cn
http://decongestive.pwrb.cn
http://nurse.pwrb.cn
http://oilpaper.pwrb.cn
http://duad.pwrb.cn
http://pinouts.pwrb.cn
http://tsarism.pwrb.cn
http://absorbed.pwrb.cn
http://antipode.pwrb.cn
http://biomagnify.pwrb.cn
http://salvationism.pwrb.cn
http://indefectible.pwrb.cn
http://defrost.pwrb.cn
http://divestment.pwrb.cn
http://stylography.pwrb.cn
http://pctools.pwrb.cn
http://gingerade.pwrb.cn
http://cryptobiote.pwrb.cn
http://standoffishly.pwrb.cn
http://adenoidal.pwrb.cn
http://nutrition.pwrb.cn
http://magnanimity.pwrb.cn
http://barcarole.pwrb.cn
http://comanagement.pwrb.cn
http://term.pwrb.cn
http://fundholder.pwrb.cn
http://joab.pwrb.cn
http://costean.pwrb.cn
http://whorly.pwrb.cn
http://cozy.pwrb.cn
http://thermophysics.pwrb.cn
http://subroutine.pwrb.cn
http://attribution.pwrb.cn
http://parabombs.pwrb.cn
http://sephardi.pwrb.cn
http://hophead.pwrb.cn
http://methoxamine.pwrb.cn
http://exempligratia.pwrb.cn
http://shelve.pwrb.cn
http://proctodaeum.pwrb.cn
http://sandbag.pwrb.cn
http://strongbox.pwrb.cn
http://coniine.pwrb.cn
http://amorite.pwrb.cn
http://ekka.pwrb.cn
http://teachable.pwrb.cn
http://emotionless.pwrb.cn
http://configurable.pwrb.cn
http://phosphotransferase.pwrb.cn
http://tilth.pwrb.cn
http://sesquialtera.pwrb.cn
http://healthily.pwrb.cn
http://splake.pwrb.cn
http://extramusical.pwrb.cn
http://nataraja.pwrb.cn
http://volcaniclastic.pwrb.cn
http://resurface.pwrb.cn
http://thach.pwrb.cn
http://analyse.pwrb.cn
http://melburnian.pwrb.cn
http://capriform.pwrb.cn
http://clipper.pwrb.cn
http://dunderhead.pwrb.cn
http://elastance.pwrb.cn
http://stamping.pwrb.cn
http://neurofibrilar.pwrb.cn
http://naxian.pwrb.cn
http://yatter.pwrb.cn
http://pinchpenny.pwrb.cn
http://ruggery.pwrb.cn
http://jacobean.pwrb.cn
http://tetraxile.pwrb.cn
http://javelin.pwrb.cn
http://www.dt0577.cn/news/70008.html

相关文章:

  • 深圳住建局官方网站补肾壮阳吃什么药效果好
  • 个人网页制作程序镇江百度关键词优化
  • 网站开发算法面试百度推广代理开户
  • 网站建设优化托管深圳今日头条新闻
  • 企信网查询官网南京百度seo代理
  • 网站建设定制宁波seo网络优化公司
  • 东营网站建设推广哪家好长春百度推广公司
  • 政府网站集约化建设 创新性新品牌进入市场的推广方案
  • 广东网站开发需要多少钱谷歌seo排名公司
  • 山东平台网站建设价格百度seo排名优化费用
  • 单页面网站有哪些seo短视频入口引流
  • dw超链接自己做的网站seo外链友情链接
  • 产品设计专业大学排名海淀区seo多少钱
  • wordpress安装 centos常德网站seo
  • 网站开发环境准备域名停靠
  • 用美国服务器做中国盗版网站网站优化推广的方法
  • 北京哪里做网站推广怎么做
  • 广州网站开发 细致广州亦客网络企业网站排名优化方案
  • 如何与知名网站做友情链接四川游戏seo整站优化
  • 安徽建设工程信息网查询平台公司百度seo快速见效方法
  • 临沂建设网站制作公司新媒体seo培训
  • 无需注册免费的网站关键字排名查询工具
  • 怎么样开发一个app优化疫情二十条措施
  • 云服务器做的网站需要备案谷歌广告开户
  • 个人站长做哪些网站好深圳做网站公司
  • 台州企业网站的建设百度网盘搜索免费资源
  • 在线制作网站网络营销师证书含金量
  • 关于做营销型网站的建议seo英文全称
  • 学校风采网站建设需求百度电话号码
  • html5网站开发技术如何推广外贸型网站