环境搭建问题

## 1.nacos可以作为注册中心和配置中心 1.错误说明 ```java Caused by: com.alibaba.nacos.api.exception.NacosException: endpoint is blank ``` >是因为没有配置配置中心的内容,但是不影响代码运行 ## 2.每次前端发送请求都得确保在gateway网关中是否有配置 ```java spring: cloud: gateway: routes: - id: ware_route uri: lb://gulimall-ware predicates: - Path=/api/ware/** filters: - RewritePath=/api/(?<segment>.*),/$\{segment} - id: admin_route uri: lb://renren-fast predicates: - Path=/api/** filters: - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment} ``` ### 2.1说明 ```txt - id: ware_route // 这个可以随便指定,到时候我们统一 - uri: lb://gulimall-ware // 这个是负载均衡到那个服务 --- > 每个服务都需要配置自己的服务名 spring.application.name = xxx - predicates: - Path=/api/ware/** // 断言 --- > 就是接受来自哪的路由 这里时来自/api/ware/**下的所有请求 - filters: // 过滤 - RewritePath=/api/(?<segment>.*),/$\{segment} --->这个就是如果一个请求时 /api/ware/test1/test2 那么我们访问后台的地址为/ware/test1/test2 ``` ## 3.服务的配置文件参考(application.yml) > 配置文件的优先级 ==**bootstarp.properties>application.yml=application.properties**== ``` spring: datasource: username: root password: root url: jdbc:mysql://192.168.56.10:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai driver-class-name: com.mysql.jdbc.Driver ## 注册中心 cloud: nacos: discovery: server-addr: 127.0.0.1:8848 jackson: date-format: yyyy-MM-dd HH:mm:ss application: name: gulimall-product ## 关闭缓存 这个项目整合了thymeleaf thymeleaf: cache: false redis: host: 192.168.56.10 port: 6379 mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto logic-delete-value: 1 logic-not-delete-value: 0 server: port: 10000 logging: level: com.atguigu.gulimall: debug ``` ## 4.服务的配置文件参考(bootstap.properties ==>一般放配置中心的配置) ```properties spring.application.name=gulimall-product spring.cloud.nacos.config.server-addr=127.0.0.1:8848 spring.cloud.nacos.config.namespace=187171bd-37a2-4188-b92b-db960010a40f ```