1 项目图(下图为gif动图):技术及框架 SpringMVC druid redis zookeeper mybatis mysql dubbo
2 自定义session管理(下图为gif动图): 在请求参数里带有sessionId,业务方法使用RequestData获取和保存数据,aop实现保存RequestData的session数据到redis中,这种session管理方式适合给接口使用
3 数据库连接池druid
4 zookeeper配置.gif
ps 4.1 java操作zookeeper的入门可以参考这篇博客(https://www.cnblogs.com/shay-zhangjin/tag/zookeeper/)
5 事务测试.gif
6 REST风格 PUT方法测试
7 dubbo-admin管理后台
这里的配置<dubbo:application name="category"/> 服务提供者和服务消费者应用名可以不一样的,主要用于依赖分析,与服务调用没有关系的。
8 使用sping-data-redis实现分布式session最终效果
8.1 代码
8.1.1 web.xml增加一个filter

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring*.xml</param-value> </context-param> <filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
8.1.2 Controller

private static final String KEY ="existAttr"; @RequestMapping("/springSession") @ResponseBody public Map<String,Object> springSession(HttpSession httpSession,String keyPart, HttpServletRequest request){ Map<String,Object> resultMap=new HashMap<>(); resultMap.put(KEY, httpSession.getAttribute(KEY)); httpSession.setAttribute(KEY,CommonUtil.generatorUUID(null)+keyPart); resultMap.put("newAttr", httpSession.getAttribute(KEY)); String server=request.getLocalAddr()+":"+request.getLocalPort(); resultMap.put("server",server); return resultMap; }
8.1.3 spring其他内容配置
可以参考这篇博客(https://www.cnblogs.com/youzhibing/p/7348337.html)
8.1.4 nginx增加配置

location /dubbostudy-web { proxy_pass http://dubbostudy-web; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } upstream dubbostudy-web{ server 192.168.10.132:8083 weight=1; server 192.168.10.132:8084 weight=1; }