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

java制作的网站广告营销是做什么的

java制作的网站,广告营销是做什么的,旅游信息网站建设论文,在网上可以做宣传的有那些网站文章目录 前言Redission详细配置步骤pom依赖application.yaml配置类CacheConfigEnvironmentContext RedissionController单测 前言 本篇博客是SpringBoot整合Redission,若文章中出现相关问题,请指出! 所有博客文件目录索引:博客…

文章目录

  • 前言
  • Redission详细配置步骤
    • pom依赖
    • application.yaml
    • 配置类
      • CacheConfig
      • EnvironmentContext
    • RedissionController
    • 单测

最新消息资讯热点围观公众号首图

前言

本篇博客是SpringBoot整合Redission,若文章中出现相关问题,请指出!

所有博客文件目录索引:博客目录索引(持续更新)

Redission集成到springboot是有两种场景的,第一个场景是针对单台节点,第二个场景是针对多台节点。

当前配置是单台节点

配套源码地址:

  • gitee:https://gitee.com/changluJava/demo-exer/tree/master/SpringBoot/springboot-redission
  • github:https://github.com/changluya/Java-Demos/tree/master/SpringBoot/springboot-redission

Redission详细配置步骤

image-20241218170628525

pom依赖

    <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.redisson</groupId><artifactId>redisson-spring-boot-starter</artifactId><version>3.17.7</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency></dependencies>

application.yaml

server:port: 8055
spring:redis:host: 127.0.0.1port: 6379database: 1password: 123456
# 直接配置参数
#redisson:
#  codec: org.redisson.codec.JsonJacksonCodec
#  threads: 4
#  netty:
#    threads: 4
#  single-server-config:
#    address: "redis://localhost:6379"
#    password: 123456
#    database: 0

配置类

CacheConfig

package com.changlu.redission.config;import io.micrometer.core.instrument.util.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class CacheConfig {@Autowiredprivate EnvironmentContext environmentContext;@Beanpublic RedissonClient redissonClient(){Config config = new Config();config.setTransportMode(TransportMode.NIO);String redisPassword = getRedisPassword();int redisDB = environmentContext.getRedisDB();// 单节点服务器SingleServerConfig singleServerConfig = config.useSingleServer();singleServerConfig.setAddress(getRedissonAddress());singleServerConfig.setDatabase(redisDB);if (StringUtils.isNotBlank(redisPassword)) {singleServerConfig.setPassword(redisPassword);}return Redisson.create(config);}private String getRedissonAddress() {return "redis://" + environmentContext.getRedisUrl() + ":" + environmentContext.getRedisPort();}public String getRedisPassword() {String redisPassword;try {redisPassword = environmentContext.getRedisPassword();} catch (Exception e) {redisPassword = environmentContext.getRedisPassword();}return redisPassword;}}

EnvironmentContext

package com.changlu.redission.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;@Component
public class EnvironmentContext {@Autowiredprivate Environment environment;public String getRedisSentinel() {return environment.getProperty("spring.redis.sentinel.nodes", "");}public int getRedisDB() {return Integer.parseInt(environment.getProperty("spring.redis.database", "1"));}public String getRedisUrl() {return environment.getProperty("spring.redis.host", "127.0.0.1");}public String getRedisPassword() {return environment.getProperty("spring.redis.password");}public int getRedisPort() {return Integer.parseInt(environment.getProperty("spring.redis.port", "6379"));}
}

RedissionController

package com.changlu.redission.controller;import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;@RestController
@RequestMapping("/redission")
public class RedissionController {@Autowiredprivate RedissonClient redissonClient;@GetMapping("/key/{key}")public Map<String, String> redission(@PathVariable("key")String key) {RLock rLock = redissonClient.getLock(key);try {boolean lock = rLock.tryLock(10, 20, TimeUnit.SECONDS);System.out.println("lock: " + lock);if (lock) {//业务Thread.sleep(1000 * 10);}} catch (Throwable e) {e.printStackTrace();} finally {if (rLock.isLocked() && rLock.isHeldByCurrentThread()) {rLock.unlock();}System.out.println("解锁");}return new HashMap<>();}}

单测

@SpringBootTest(classes = SpringbootRedissionApplication.class)
@RunWith(SpringRunner.class)
public class TestApplication {@AutowiredApplicationContext context;// redisson客户端@AutowiredRedissonClient redissonClient;// 测试分布式锁@Testpublic void terst1() throws InterruptedException {RLock lock = redissonClient.getLock("anyLock");new Thread(() -> {lock.lock();try {System.out.println(Thread.currentThread().getName() + ":\t 获得锁");Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();} finally {System.out.println(Thread.currentThread().getName() + ":\t 释放锁");lock.unlock();}}).start();new Thread(() -> {lock.lock();try {System.out.println(Thread.currentThread().getName() + ":\t 获得锁");Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();} finally {System.out.println(Thread.currentThread().getName() + ":\t 释放锁");lock.unlock();}}).start();Thread.sleep(100000);}
}
http://www.hkea.cn/news/514871/

相关文章:

  • 长宁专业做网站网络营销案例分享
  • 哈尔滨专业建网站哪家好码迷seo
  • 涞水县住房和城乡建设局网站厦门seo专业培训学校
  • 网站建设销售招聘德阳seo
  • 平台网站建设的公司seozou是什么意思
  • wordpress 相册 主题seo整站优化技术培训
  • 做窗帘网站图片百度自动点击器下载
  • 飘雪影视大全免费观看视频快推达seo
  • 做网站的装饰标语seo宣传网站
  • 国外 平面设计 网站百度收录
  • 做网站话术简述搜索引擎的工作原理
  • 现在建设网站赚钱吗seo外链论坛
  • 青海网站建设企业海南百度竞价推广
  • 南京做网站yuanmus电脑突然多了windows优化大师
  • 美国做deals的网站软文营销经典案例优秀软文
  • 招标网站怎么做吴江seo网站优化软件
  • 苏州建设工程协会网站seo去哪里学
  • 上海正规网站制作价格可口可乐软文营销案例
  • 番禺网站 建设信科网络站长之家ping
  • 建筑工程施工承包合同关键词优化报价推荐
  • 网站可以免费看企业网站系统
  • 中华人民共和国建设部网站seo怎么快速提高排名
  • 南宁做网站的有几家东莞网络营销网站建设
  • 苏州知名网站建设开发新区seo整站优化公司
  • 政府建设网站计划书品牌营销策略包括哪些内容
  • 深圳市做网站百度seo排名点击器app
  • 五莲网站建设维护推广网络营销推广及优化方案
  • 重庆网红整站多关键词优化
  • 动易网站cms一级消防工程师考试
  • wordpress更新报错想找搜索引擎优化