✅P236_商城业务-购物车-环境搭建
大约 2 分钟
搭建购物车服务
创建工程
pom依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gyz.cfmall</groupId>
<artifactId>cfmall-cart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cfmall-cart</name>
<description>购物车服务</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.gyz.cfmall</groupId>
<artifactId>cfmall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
server:
port: 9100
spring:
application:
name: cfmall-cart
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
redis:
host: 192.168.56.10
port: 6379
启动类
package com.gyz.cfmall;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
public class CfmallCartApplication {
public static void main(String[] args) {
SpringApplication.run(CfmallCartApplication.class, args);
}
}
域名配置
C:\Windows\System32\drivers\etc\host
文件新增如下配置:
192.168.17.130 cart.cfmall.com
Nginx动静分离资源配置
上传本地静态资源到/mydata/nginx/html/static/cart/目录下
复制cartList.html和success.html至cfmall-cart/src/main/resources/templates下
修改静态资源访问路径
cartList.html
和success.html
都需要修改!
href=". 替换为 href="/static/cart
src=". 替换为 src="/static/cart
修改页面跳转路径
cartList.html
<div class="one_top_left">
<a href="http://cfmall.com" class="one_left_logo"><img src="img/logo1.jpg"></a>
<a href="#" class="one_left_link">购物车</a>
</div>
配置网关
cfmall-gateway/src/main/resources/application.yml
- id: cfmall-cart-route
uri: lb://cfmall-cart
predicates:
- Host=cart.cfmall.com