项目结构
一:服务管理(dcb-lott-service)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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dcb-lott-app</artifactId>
<groupId>com.dcb</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modules>
<module>dcb-lott-activety</module>
<module>dcb-lott-sso</module>
</modules>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>dcb-lott-service</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</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-ribbon</artifactId>
</dependency>
<!-- 自己封装的工具包,需手动去除 -->
<dependency>
<groupId>com.dcb</groupId>
<artifactId>common-utils</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.9</version>
</dependency>
</dependencies>
</project>
二:服务提供者(单个的服务既可以为服务提供者,也可为服务消费者)pom文件
<dependencies>
<!-- 服务提供者所需依赖,由于所有单个服务交由dcb-lott-service管理,故将其作为公共依赖加入父级
此处无需再加入依赖,如若不需要父级管理则必须引入此依赖包
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
-->
</dependencies>
在spring boot启动类加上@EnableEurekaClient
注解
/**
* @Auther: yxc
* @Date: 2018/8/1 10:47
* @Description:
*/
@EnableEurekaClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
服务提供者application.yml
eureka:
client:
#服务提供者需指定注册中中心地址d
serviceUrl:
defaultZone: http://localhost:8080/eureka/
server:
port: 8081
spring:
application:
name: dcb-lott-sso
注意:
2.服务提供者spring.application.name
尤为重要,之后的服务消费者都需要通过此配置寻找服务
接下来启动服务提供者,必须先启动注册中心,在注册中心界面即可查看服务提供者信息
可再启动一个服务,将端口改为8082,用于负载均衡的调用。