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

黄冈商城网站制作哪家好潍坊网络营销外包

黄冈商城网站制作哪家好,潍坊网络营销外包,想学做电商怎么加入,网站建设方案概述背景#xff1a; 之前一直只考虑用JavaSe进行游戏服务器开发#xff0c;目前项目使用了Spring#xff0c;发现还是非常好的#xff0c;好处如下: 好处1:依赖注入非常方便#xff0c;我们只使用Spring最基本的功能即可#xff0c;这样子就算是有一些模块不使用Spring管理…背景 之前一直只考虑用JavaSe进行游戏服务器开发目前项目使用了Spring发现还是非常好的好处如下: 好处1:依赖注入非常方便我们只使用Spring最基本的功能即可这样子就算是有一些模块不使用Spring管理也是非常方便的因为我现在已经能轻松控制住Spring容器的声明周期。 好处2: 模块之间就像搭建积木即可又相互配合。 我想支持web也是非常轻松。 好处3: 这样子再去整合Mybatis、或者其它的一些MQ、ES之类的中间件就太简单了。 pom.xml   // 项目中使用了lettuce这里作为演示 dependencygroupIdio.lettuce/groupIdartifactIdlettuce-core/artifactIdversion5.1.8.RELEASE/version/dependencydependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactId!--起码1.2.48以上因为这个版本一下存在漏洞--version1.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(ClassT 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 MapString, 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{num1, map{k6666}}
http://www.hkea.cn/news/14338952/

相关文章:

  • 智慧团建登录网站入口网页设计基础的课程介绍
  • 三门峡住房和建设局网站牡丹江市建设行业协会网站
  • 南京旅游网站建设公司网站建设编码
  • 台州平台网站建设公司注册地址可以跨市变更吗
  • 南昌旅游集团网站建设河北建设工程交易信息网
  • 公司对网站排名如何做绩效263企业邮箱app下载官网
  • 网站模板尺寸百度广告平台电话
  • 网站开发 附加协议在线免费货源网站入口
  • 可以做用户旅程图的网站中国各大网站名称
  • 简单网站后台兰州光辉网站建设
  • 浙江国泰建设集团有限公司网站psd to wordpress
  • 中山cms建站模板室内设计师联盟账号
  • 如何快速做一个网站布吉做棋牌网站建设哪家技术好
  • 奉节网站建设公司响应式网站建设对企业营销
  • 个人做旅游网站怎样宁夏建设厅网站6
  • 网站开发的职业认知报告wordpress 什么值得买 我要爆料
  • 网站建设是设教学网站在线自测功能怎么做
  • 洞头区小程序模板源代码企业排名优化公司
  • 网站建设需要域名网站外部优化的4大重点
  • 商品网站做推广成都多语种网站建设
  • 注册网站刀具与钢材经营范围义乌网红村
  • 网站怎么样做优化去了外包公司就毁了吗
  • 怎么创建一个网站卖东西巢湖网站建设电话
  • 零售网站建设方案教人做家务的网站
  • 免费的网站如何建设史志网站建设
  • 郑州做网站zztuotian网站优化的内容
  • 西安大兴医院网站建设完成网站建设的心得体会
  • 淘宝客怎么做自己网站推广微网站微商城建设
  • 东莞创建网站软文推广的作用
  • 淘客必须做网站灌云网站制作