spring cloud构建b2b2c分布式-搭建eureka服务

為{幸葍}努か 提交于 2020-01-16 03:17:09

1.pom.xml

有spring cloud b2b2c电子商务需求的朋友可以加企鹅求求:三五三六二四七二五九

<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">  
<modelVersion>4.0.0</modelVersion>  

<groupId>com.hive</groupId>  
<artifactId>user-eureka</artifactId>  
<version>0.0.1-SNAPSHOT</version>  
<packaging>jar</packaging>  

<name>eureka_user</name>  
<url>http://maven.apache.org</url>  

<parent>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-parent</artifactId><!--配合spring cloud版本-->  
<version>1.4.3.RELEASE</version>  
</parent>  

<!--设置字符编码及java版本-->  
<properties>  
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  

<java.version>1.8</java.version>  
</properties>  
<dependencies>  

<!--增加eureka-server的依赖-->  
<dependency>  
<groupId>org.springframework.cloud</groupId>  
<artifactId>spring-cloud-starter-eureka-server</artifactId>  
</dependency>  
</dependencies>  

<!--依赖管理,用于管理spring-cloud的依赖-->  
<dependencyManagement>  
<dependencies>  
<dependency>  
<groupId>org.springframework.cloud</groupId>  
<artifactId>spring-cloud-dependencies</artifactId>  
<version>Camden.SR1</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>  

2.application

package com.hivescm;  

import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication;  
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;  

@SpringBootApplication//springBoot注解,spring在springBoot基础之上来构建项目  
@EnableEurekaServer//开启eureka服务  
public class EurekaApplication {  
public static void main(String[] args) {  

//spirng boot的标准入口  
SpringApplication.run(EurekaApplication.class, args);  
}  
}  

3.application.yml

server:  
port: 8761#指定服务端口  
eureka:  
client:  
register-with-eureka: false #是否将eureka自身作为应用注册到eureka注册中心  
fetch-registry: false #为true时,可以启动,但报异常:Cannot execute request on any known server  
service-url:  
defaultZone: http://192.168.106.49:8761/eureka  

简单的eureka就写好了,运行下EurekaApplication .java

访问:http://localhost:8761/有spring cloud b2b2c电子商务需求的朋友可以加企鹅求求:三五三六二四七二五九

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!