eureka服务端依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
eureka服务端yml配置:
server:
port: 1010 #端口
eureka:
instance:
hostname: localhost #主机
client: #客户端配置
registerWithEureka: false #EurekaServer自己不要注册到EurekaServer自己 ,只有EurekaClient才注册
fetchRegistry: false #EurekaServer不要拉取服务的通信地址列表 ,只有EurekaClient才拉取地址列表
serviceUrl: #注册中心的注册地址
defaultZone: http://localhost:1010/eureka/ #http://${eureka.instance.hostname}:${server.port}/eureka/
server:
enable-self-preservation: false #关闭自我保护警告
主启动类上打上注解:
@EnableEurekaServer
eureka客户端依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
eureka客户端yml配置:
eureka:
client:
serviceUrl: #链接eureka服务端
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true # 开启使用IP地址进行注册
instance-id: 商品服务:${server.port}# 修改实例Id
spring:
datasource:
username: root
password: 111111
url: jdbc:mysql:///mybatis0806?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
application: # 指定此服务的应用名称
name: product-server
server:
port: 1010 # user服务端口号
mybatis:
type-aliases-package: cn.wangjiaojiao.domain
configuration:
map-underscore-to-camel-case: true
feign:
hystrix:
enabled: true #开启熔断支持
整合mybatis和openfeign的依赖:
<dependencies>
<!--引入Eureka的客户端依赖,不包含springboot-start-web,所以要单独引入-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--引入springboot-start-web依赖,必须引入-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>cn.wangjiaojiao</groupId>
<artifactId>common-server</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- spring-boot整合mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!--引入OpenFeign依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>