1.乐优商城项目搭建
前端技术:
基础的HTML、CSS、JavaScript(基于ES6标准)
JQuery
Vue.js 2.0以及基于Vue的框架:Vuetify
前端构建工具:WebPack
前端安装包工具:NPM
Vue脚手架:Vue-cli
Vue路由:vue-router
ajax框架:axios
基于Vue的富文本框架:quill-editor
后端技术:
基础的SpringMVC、Spring 5.0和MyBatis3
Spring Boot 2.0.1版本
Spring Cloud 最新版 Finchley.RC1
Redis-4.0
RabbitMQ-3.4
Elasticsearch-5.6.8
nginx-1.10.2:
FastDFS - 5.0.8
MyCat
Thymeleaf
2.开发环境
IDE:我们使用Idea 2019 版本
JDK:统一使用JDK1.8
项目构建:maven3.3.9以上版本即可
版本控制工具:git
3.域名
我们在开发的过程中,为了保证以后的生产、测试环境统一。尽量都采用域名来访问项目。
一级域名:www.leyou.com
二级域名:manage.leyou.com , api.leyou.com
4.创建父工程
4.1 创建统一的父工程:leyou,用来管理依赖及其版本。
4.2 Ly-common:通用工具模块存放一些通用的工具类,异常处理类等
4.3 Ly-item:Ly-item-interface:主要是对外暴露的接口及相关实体类
Ly-item-service:所有业务逻辑及内部使用接口
4.4 LyEureka:注册中心,微服务之间的通信
4.5 LyZuul:网关。作为Zuul我们服务的统一入口
4.1:父工程的搭建
pom.xml
<groupId>com.leyou.parent</groupId>
<artifactId>leyou</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>LyEureka</module>
<module>LyZuul</module>
<module>Ly-item</module>
<module>Ly-common</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RC1</spring-cloud.version>
<mybatis.starter.version>1.3.2</mybatis.starter.version>
<mapper.starter.version>2.0.2</mapper.starter.version>
<druid.starter.version>1.1.9</druid.starter.version>
<mysql.version>5.1.32</mysql.version>
<pageHelper.starter.version>1.2.3</pageHelper.starter.version>
<leyou.latest.version>1.0.0-SNAPSHOT</leyou.latest.version>
<fastDFS.client.version>1.26.1-RELEASE</fastDFS.client.version>
<lombok.version>1.18.8</lombok.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- springCloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- mybatis启动器 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.starter.version}</version>
</dependency>
<!-- 通用Mapper启动器 -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>${mapper.starter.version}</version>
</dependency>
<!-- 分页助手启动器 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pageHelper.starter.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--FastDFS客户端-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>${fastDFS.client.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
4.2 Ly-common的搭建
pom.xml
<groupId>com.leyou.common</groupId>
<artifactId>Ly-common</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>
4.3 Ly-item的搭建
pom.xml
<groupId>com.leyou.service</groupId>
<artifactId>Ly-item</artifactId>
<packaging>pom</packaging>
<modules>
<module>Ly-item-interface</module>
<module>Ly-item-service</module>
</modules>
Ly-item-interface的搭建
pom.xml
<groupId>com.leyou.service</groupId>
<artifactId>Ly-item-interface</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
Ly-item-service的搭建
pom.xml
<groupId>com.leyou.service</groupId>
<artifactId>Ly-item-service</artifactId>
<dependencies>
<!--导入接口-->
<dependency>
<groupId>com.leyou.service</groupId>
<artifactId>Ly-item-interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.leyou.common</groupId>
<artifactId>Ly-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
application.yaml
server:
port: 8001
spring:
application:
name: item-service
datasource:
url: jdbc:mysql://localhost:3306/leyou
username: root
password: 12345
hikari:
maximum-pool-size: 30
minimum-idle: 10
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秒不发送就过期
prefer-ip-address: true
ip-address: 127.0.0.1
instance-id: ${spring.application.name}:${server.port}
起步类
LyItemApplication.class
@EnableDiscoveryClient
@SpringBootApplication
public class LyItemApplication {
public static void main(String[] args) {
SpringApplication.run(LyItemApplication.class);
}
}
4.4 LyEureka的搭建
pom.xml
<groupId>com.leyou.common</groupId>
<artifactId>Ly-Eureka</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
application.yaml
server:
port: 10086
spring:
application:
name: lyEureka
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:10086/eureka
#不对自己进行拉取 不会注册自己
fetch-registry: false
register-with-eureka: false
#defaultZone: http://127.0.0.1:${server.port}/eureka
起步类LyEureka.class
@EnableEurekaServer
@SpringBootApplication
public class LyEureka {
public static void main(String[] args) {
SpringApplication.run(LyEureka.class);
}
}
4.5 LyZuul的搭建
pom.xml
<groupId>com.leyou.common</groupId>
<artifactId>LyZuul</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--是springboot提供的微服务检测接口,默认对外提供几个接口:/info-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
application.yaml
server:
port: 10010
spring:
application:
name: lyZuul
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:10086/eureka
registry-fetch-interval-seconds: 10 #网关拉取的周期
registry-fetch-interval-seconds: 5
instance:
prefer-ip-address: true
ip-address: 127.0.0.1
instance-id: ${spring.application.name}:${server.port}
zuul:
prefix: /api # 添加路由前缀
routes:
item-service: /item/**
ribbon:
ConnectTimeout: 1000 # 连接超时时间(ms)
ReadTimeout: 3500 # 通信超时时间(ms)
MaxAutoRetriesNextServer: 0 # 同一服务不同实例的重试次数
MaxAutoRetries: 0 # 同一实例的重试次数
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMillisecond: 5000 # 熔断超时时长:10000ms
起步类LyZuulApplication.class
@EnableZuulProxy
@SpringCloudApplication
public class LyZuulApplication {
public static void main(String[] args) {
SpringApplication.run(LyZuulApplication.class);
}
}
启动测试
手机扫一扫
移动阅读更方便
你可能感兴趣的文章