PUTproduct{"mappings":{"properties":{"skuId":{"type":"long"},"spuId":{"type":"keyword"},"skuTitle":{"type":"text","analyzer":"ik_smart"},"skuPrice":{"type":"keyword"},"skuImg":{"type":"keyword","index":false,"doc_values":false},"saleCount":{"type":"long"},"hasStock":{"type":"boolean"},"hotScore":{"type":"long"},"brandId":{"type":"long"},"catalogId":{"type":"long"},"brandName":{"type":"keyword","index":false,"doc_values":false},"brandImg":{"type":"keyword","index":false,"doc_values":false},"catalogName":{"type":"keyword","index":false,"doc_values":false},"attrs":{"type":"nested","properties":{"attrId":{"type":"long"},"attrName":{"type":"keyword","index":false,"doc_values":false},"attrValue":{"type":"keyword"}}}}}}2.首页项目的页面视图部署在对应的微服务项目的静态资源中
添加thymeleaf的依赖
packagecom.yxw.gulimall.product.config;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;/***SimpletoIntroduction*className:WebMVCConfig**@authoryanxw*@version2023/12/147:57AM*/@ConfigurationpublicclassWebMVCConfigextendsWebMvcConfigurerAdapter{@OverridepublicvoidaddResourceHandlers(ResourceHandlerRegistryregistry){registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");}}2.去掉index.html路径里面的static
编辑操作hosts文件
192.168.0.88gulimall.com保存成功之后可以直接访问域名,解析到虚拟机的ipTips:有科学上网的测试的时候要先关闭科学上网的软件安装了ES的访问gulimall.com:9200可以看到相应的内容正式搭建项目的域名访问环境1.nginx的配置文件配置nginx
#切换到nginx挂载在本机的配置文件所在的目录cd/mydata/nginx/conf#切换到nginx的分配置文件下复制一份定义gulimall的配置,主配置文件中有include/etc/nginx/conf.d/*.conf;这么一段配置,主配置文件#会包含conf.d目录下的所有配置cd/mydata/nginx/conf/conf.dcpdefault.confgulimall.conf复制一份#在gulimall.conf配置文件中配置我们的配置#配置如下配置niginx的配置文件如下
dockerrestartnginx2.让nginx代理到网关在nginx.conf配置文件中加上如下的配置
#gulimall是上游服务器的组名upstreamgulimall{#网关的地址注意这里是自己本机的ip,不是服务器ipserver192.168.0.112:88;}修改gulimall.conf中的配置
在网关的配置文件中加上以下的配置
-id:gulimall_host_routeuri:lb://mall-productpredicates:-Host=**.gulimall.com这时我们重启网关的时候发现无法访问到相应的页面是由于nginx访问网关的时候丢了host这时我们需要加上如下的配置
proxy_set_headerHost$host;
jconsolejvisualvm我用的是jvisualvm
监控内存泄露,跟踪垃圾回收,执行时内存、cpu分析,线程分析...运行:正在运行的休眠:sleep等待:wait驻留:线程池里面的空闲线程监视:阻塞的线程,正在等待锁
现在服务器nginx目录创建文件夹如下将mall-product服务下的index文件夹上传到刚才创建的static文件夹下,同时删除mall-product服务下的index文件夹修改nginx配置修改nginx后要重启dockerrestartnginx
Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理。它支持字符串、哈希表、列表、集合、有序集合,位图,hyperloglogs等数据类型。内置复制、Lua脚本、LRU收回、事务以及不同级别磁盘持久化功能,同时通过RedisSentinel提供高可用,通过RedisCluster提供自动分区。
application.properties
下面的第一个方法是查询数据位list集合
@Cacheable(value=“dict”,keyGenerator=“keyGenerator”)对方法的结果进行缓存
value属性表示key的前缀
keyGenerator表示key的生成规则,生成规则在配置文件中配置,这里我们使用的是方法的全类名作为key的后缀
第二个方法是添加数据添加数据会造成数据库中数据的变化我们要清除缓存
@CacheEvict(value=“dict”,allEntries=true)清空指定的缓存
value属性表示清空以dict为前缀的所有缓存
allEntries属性表示是否清空所有缓存,默认为false。如果指定为true,则方法调用后将立即清空所有的缓存
1)、springboot2.0以后默认使用lettuce作为操作redis的客户端,它使用netty进行网络通信
2)、lettuce的bug导致netty堆外内存溢出。netty如果没有指定堆外内存,默认使用Xms的值,可以使用-Dio.netty.maxDirectMemory进行设置
解决方案:由于是lettuce的bug造成,不要直接使用-Dio.netty.maxDirectMemory去调大虚拟机堆外内存,治标不治本。
1)、升级lettuce客户端2)、切换使用jedis修改依赖文件,使用jedis作为客户端工具
在nginx里面放入如下文件
server{
网关配置
修改nginx配置
按照条件查询
GETgulimall_product/_search{"query":{"match_all":{}},"aggs":{"brand_agg":{"terms":{"field":"brandId","size":10},"aggs":{"brand_name_aggs":{"terms":{"field":"brandName","size":10}}}},"catalog_agg":{"terms":{"field":"catalogId","size":10}}}}报错不能加载brandName数据,因为这个数据不支持keyword类型,解决办法修改映射和迁移数据:创建索引mall_product
PUTmall_product{"mappings":{"properties":{"skuId":{"type":"long"},"spuId":{"type":"keyword"},"skuTitle":{"type":"text","analyzer":"ik_smart"},"skuPrice":{"type":"keyword"},"skuImg":{"type":"keyword"},"saleCount":{"type":"long"},"hasStock":{"type":"boolean"},"hotScore":{"type":"long"},"brandId":{"type":"long"},"catalogId":{"type":"long"},"brandName":{"type":"keyword"},"brandImg":{"type":"keyword"},"catalogName":{"type":"keyword"},"attrs":{"type":"nested","properties":{"attrId":{"type":"long"},"attrName":{"type":"keyword"},"attrValue":{"type":"keyword"}}}}}}数据迁移:
POST_reindex{"source":{"index":"gulimall_product"},"dest":{"index":"mall_product"}}完整的dsl语句:
@EnableFeignClients@EnableDiscoveryClient@SpringBootApplicationpublicclassMallAuthServerApplication{publicstaticvoidmain(String[]args){SpringApplication.run(MallAuthServerApplication.class,args);}}application.yml
修改application.yml
thymeleaf:cache:false创建LoginController
创建GulimallWebConfig类
packagecom.yxw.gulimall.auth.config;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.ViewControllerRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;/***SimpletoIntroduction*className:GulimallWebConfig**@authoryanxw*@version2023/12/315:22PM*/@ConfigurationpublicclassGulimallWebConfigimplementsWebMvcConfigurer{/**·*视图映射:发送一个请求,直接跳转到一个页面*@paramregistry*/@OverridepublicvoidaddViewControllers(ViewControllerRegistryregistry){registry.addViewController("/login.html").setViewName("login");registry.addViewController("/reg.html").setViewName("reg");}}