整个商城可分为:后台管理系统,前台管理系统
前端技术:
后端技术:
4.0.0
com.leyou.parent
leyou
1.0.0-SNAPSHOT
pom
leyou
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.7.RELEASE
UTF-8
UTF-8
1.8
Finchley.SR2
1.3.2
2.0.2
1.1.9
5.1.32
1.2.3
1.0.0-SNAPSHOT
1.26.1-RELEASE
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.mybatis.spring.boot
mybatis-spring-boot-starter
${mybatis.starter.version}
tk.mybatis
mapper-spring-boot-starter
${mapper.starter.version}
com.github.pagehelper
pagehelper-spring-boot-starter
${pageHelper.starter.version}
mysql
mysql-connector-java
${mysql.version}
com.github.tobato
fastdfs-client
${fastDFS.client.version}
org.springframework.boot
spring-boot-maven-plugin
## 创建注册中心leyou-registry pom.xml如下所示
leyou
com.leyou.parent
1.0.0-SNAPSHOT
4.0.0
com.leyou.common
leyou-registry
1.0.0-SNAPSHOT
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
## 编写启动类 @SpringBootApplication @EnableEurekaServer public class LeyouRegistryApplication {
public static void main(String[] args) {
SpringApplication.run(LeyouRegistryApplication.class, args);
}
}
server:
port: 10086
spring:
application:
name: leyou-registry
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:${server.port}/eureka
register-with-eureka: false # 把自己注册到eureka服务列表
fetch-registry: false # 拉取eureka服务信息
server:
enable-self-preservation: false # 关闭自我保护
eviction-interval-timer-in-ms: 5000 # 每隔5秒钟,进行一次服务列表的清理
pom.xml下所示
leyou
com.leyou.parent
1.0.0-SNAPSHOT
4.0.0
com.leyou.common
leyou-gateway
1.0.0-SNAPSHOT
org.springframework.cloud
spring-cloud-starter-netflix-zuul
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-actuator
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class LeyouGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(LeyouGatewayApplication.class, args);
}
}
server:
port: 10010
spring:
application:
name: leyou-gateway
eureka:
client:
registry-fetch-interval-seconds: 5
service-url:
defaultZone: http://127.0.0.1:10086/eureka
zuul:
prefix: /api # 路由路径前缀
我们会在leyou-item中创建两个子工程
leyou-item-interface:主要是对外暴露的接口及相关实体类
leyou-item-service:所有业务逻辑及内部使用接口
结构如下:
leyou-item
com.leyou.item
1.0.0-SNAPSHOT
4.0.0
com.leyou.item
leyou-item-service
1.0.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.mybatis.spring.boot
mybatis-spring-boot-starter
tk.mybatis
mapper-spring-boot-starter
com.github.pagehelper
pagehelper-spring-boot-starter
org.springframework.boot
spring-boot-starter-jdbc
mysql
mysql-connector-java
com.leyou.item
leyou-item-interface
1.0.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-actuator
@SpringBootApplication
@EnableDiscoveryClient
public class LeyouItemServiceApplication {
public static void main(String[] args) {
SpringApplication.run(LeyouItemServiceApplication.class, args);
}
}
server:
port: 8081
spring:
application:
name: item-service
datasource:
url: jdbc:mysql://localhost:3306/leyou
username: root
password: root
hikari:
max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like ‘%timeout%’;)
maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:10086/eureka
instance:
lease-renewal-interval-in-seconds: 5 # 5秒钟发送一次心跳
lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期
修改leyou-gateway工程的application.yml配置文件:
zuul:
prefix: /api # 路由路径前缀
routes:
item-service: /item/** # 商品微服务的映射路径
leyou-common