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

wordpress怎么做站群怎样自学开网店

wordpress怎么做站群,怎样自学开网店,那里可以做旅游网站的吗,网站用什么好背景: 之前一直只考虑用JavaSe进行游戏服务器开发,目前项目使用了Spring,发现还是非常好的,好处如下: 好处1:依赖注入非常方便,我们只使用Spring最基本的功能即可,这样子就算是有一些模块不使用Spring管理…

背景:

之前一直只考虑用JavaSe进行游戏服务器开发,目前项目使用了Spring,发现还是非常好的,好处如下:

        好处1:依赖注入非常方便,我们只使用Spring最基本的功能即可,这样子就算是有一些模块不使用Spring管理也是非常方便的,因为我现在已经能轻松控制住Spring容器的声明周期。

        好处2: 模块之间就像搭建积木即可,又相互配合。 我想支持web也是非常轻松。

        好处3: 这样子再去整合Mybatis、或者其它的一些MQ、ES之类的中间件,就太简单了。

pom.xml   // 项目中使用了lettuce,这里作为演示

       <dependency><groupId>io.lettuce</groupId><artifactId>lettuce-core</artifactId><version>5.1.8.RELEASE</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><!--(起码1.2.48以上)因为这个版本一下存在漏洞--><version>1.2.48</version></dependency>

1.Application.java

package com.example.springbootgame.application;import org.springframework.context.ApplicationContext;public class Application {private static ApplicationContext applicationContext;public static ApplicationContext getApplicationContext() {return applicationContext;}public static void setApplicationContext(ApplicationContext applicationContext) {Application.applicationContext = applicationContext;}public static <T> T getBean(Class<T> requiredType) {if (applicationContext == null) {return null;}return applicationContext.getBean(requiredType);}}

2.RedisConfig.java // 使用Configuration引入一些自定义的Bean

package com.example.springbootgame.config;import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.sync.RedisCommands;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.time.Duration;
import java.time.temporal.ChronoUnit;@Configuration
public class RedisConfig {@Beanpublic GameRedis getGameRedis() {RedisURI redisURI = RedisURI.builder().withHost("localhost").withPort(6379).withTimeout(Duration.of(10, ChronoUnit.SECONDS)).build();RedisClient redisClient = RedisClient.create(redisURI);return new GameRedis(redisClient.connect().sync());}
}

3.GameRedis.java // 包装器模式。包装出自己的访问接口

package com.example.springbootgame.config;import io.lettuce.core.api.sync.RedisCommands;public class GameRedis {private RedisCommands redisCommands;public GameRedis(RedisCommands redisCommands) {this.redisCommands = redisCommands;}public <K, V> V get(K k) {return (V) redisCommands.get(k);}public <K, V> void set(K k, V v) {redisCommands.set(k, v);}
}

4.LoginHandler.java

package com.example.springbootgame.handler;import com.alibaba.fastjson.JSON;
import com.example.springbootgame.config.GameRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;import java.util.HashMap;
import java.util.Map;@Controller
public class LoginHandler {@AutowiredGameRedis gameRedis;/*** 玩家登录*/public void onCSLogin() {// 简单类型gameRedis.set("123", "abc");String v = gameRedis.get("123");System.out.println(v);// 复杂类型Data data = new Data();data.map.put("k", 6666);gameRedis.set("obj", JSON.toJSONString(data));Data obj = JSON.parseObject(gameRedis.get("obj"), Data.class);System.out.println(obj);}private static class Data {public int num = 1;public Map<String, Integer> map = new HashMap<>();@Overridepublic String toString() {return "Data{" +"num=" + num +", map=" + map +'}';}}
}

5.GameServer.java

package com.example.springbootgame;import com.example.springbootgame.application.Application;
import com.example.springbootgame.handler.LoginHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;import java.io.IOException;@SpringBootApplication
@Slf4j
public class GameServer {public static void registerShutdownHook() {Runtime.getRuntime().addShutdownHook(new Thread(() -> {log.info("gs shutdown in {}", Thread.currentThread().getName());// 测试bean的获取LoginHandler loginHandler = Application.getBean(LoginHandler.class);loginHandler.onCSLogin();// 关闭Spring容器ApplicationContext applicationContext = Application.getApplicationContext();if (applicationContext != null) {ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext;cac.close();}}, "ShutdownHook-GameServer-Thread"));}public static void main(String[] args) {registerShutdownHook();// 启动Spring容器ApplicationContext applicationContext = SpringApplication.run(GameServer.class, args);Application.setApplicationContext(applicationContext);// 初始化各个模块,如:进行handler的扫描// 阻塞关服try {System.in.read();} catch (IOException e) {log.error("exception", e);}}}
  .   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::               (v2.7.17)2023-11-18 20:56:48.393  INFO 7056 --- [           main] com.example.springbootgame.GameServer    : Starting GameServer using Java 11.0.11 on DESKTOP-JTMBOEI with PID 7056 (D:\2_test_java\SpringBootGame\target\classes started by Administrator in D:\2_test_java\SpringBootGame)
2023-11-18 20:56:48.397  INFO 7056 --- [           main] com.example.springbootgame.GameServer    : No active profile set, falling back to 1 default profile: "default"
2023-11-18 20:56:48.960  INFO 7056 --- [           main] io.lettuce.core.EpollProvider            : Starting without optional epoll library
2023-11-18 20:56:48.961  INFO 7056 --- [           main] io.lettuce.core.KqueueProvider           : Starting without optional kqueue library
2023-11-18 20:56:49.492  INFO 7056 --- [           main] com.example.springbootgame.GameServer    : Started GameServer in 1.512 seconds (JVM running for 2.701)
1
2023-11-18 20:56:50.723  INFO 7056 --- [meServer-Thread] com.example.springbootgame.GameServer    : gs shutdown in ShutdownHook-GameServer-Thread
abc
Data{num=1, map={k=6666}}

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

相关文章:

  • 1688网站怎么样百度开放平台 wordpress
  • 旅游网站开发的作用wordpress如何改字体
  • 重庆手机网站制作费用哈尔滨快速制作网站
  • 帮做装修设计的网站找房网58同城买房
  • 深圳制作网站建设多用户建站平台
  • 兰州新区农投建设网站wordpress 前台帖子
  • 番禺区建设局网站建立com网站
  • 电子商务网站建设 概念工商管理局注册查询
  • 网站前后端分离怎么做微信做自己网站
  • 织梦制作手机网站怎么去除自己做的网站
  • 织梦网站关掉wap网站开发需要注意什么
  • 手机支付网站开发有关互联网网站
  • 网站开发验收过程电脑做网站服务器
  • 长沙模板建站源码app推广软件
  • 浙江省建设项目招投标网站怎么用自己电脑当服务器建设网站
  • 北京做网站youyi51开公众号需要多少钱
  • 做视频类网站需要哪些许可证wordpress 前台 很慢
  • 网站建设制作设计推广具有价值的建网站
  • 没有公网ip建设网站东盟建设集团有限公司网站
  • 一般建一个外贸网站多少钱黄页网站软件下载免费app
  • 自己做qq头像的网站idea网站开发
  • 安徽建设工程信息网新网站哪儿登陆山东通app下载安装2022
  • 网站如何做做期货网站违法的吗
  • 常用网站代码电子报 网站开发
  • 优秀app网站设计计算机多媒体辅助教学网站开发
  • 建设银行集团网站首页国内营销公司排名
  • 教育网站图片wordpress怎么设置自己的模板
  • 自助建站系统个人网站世界500强企业logo图片
  • 微信网站建站平台wordpress 早起文章
  • 上海高端网站开发公司建设民政局网站需要多少钱