赞
踩
先创建一个maven项目
导入springboot springcloud和Eureka相关依赖
依赖这里一直有错误,改了半天才可以用 ,用的是阿里云的仓库下载的。
- <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.vhukze.Eureka</groupId>
- <artifactId>Eureka</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>Eureka</name>
-
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-parent</artifactId>
- <version>2.0.3.RELEASE</version>
- </parent>
- <!-- 管理依赖 -->
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>Finchley.M7</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <!--SpringCloud eureka-server -->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
- </dependency>
- </dependencies>
-
- <!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
-
- <repositories>
- <repository>
- <id>spring-milestones</id>
- <name>Spring Milestones</name>
- <url>https://repo.spring.io/milestone</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <repository>
- <id>repository.springframework.maven.release</id>
- <name>Spring Framework Maven Release Repository</name>
- <url>http://maven.springframework.org/milestone/</url>
- </repository>
- <repository>
- <id>org.springframework</id>
- <url> http://maven.springframework.org/snapshot</url>
- </repository>
- <repository>
- <id>spring-milestone</id>
- <name>Spring Maven MILESTONE Repository</name>
- <url>http://repo.spring.io/libs-milestone</url>
- </repository>
- <repository>
- <id>spring-release</id>
- <name>Spring Maven RELEASE Repository</name>
- <url>http://repo.spring.io/libs-release</url>
- </repository>
- </repositories>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
resources下的application.yml 文件
- #服务端口号
- server:
- port: 8100
- eureka:
- instance:
- #注册中心ip
- hostname: 127.0.0.1
- client:
- serviceUrl:
- #注册地址
- defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
- #是否需要把吧本项目注册到注册中心
- register-with-eureka: false
- #因为自己是注册中心 所以不需要检索服务
- fetch-registry: false
然后写一个启动类
-
- package com.vhukze.app;
-
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
- import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
-
- /**
- * @author zsz
- * @version
- * @创建时间:2019年10月9日 上午8:52:42
- */
- @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
- @EnableEurekaServer
- public class EurekaApp {
-
- //@EnableEurekaServer表示开启服务 开启注册中心
-
- public static void main(String[] args) {
- SpringApplication.run(EurekaApp.class, args);
- }
- }
启动项目访问localhost:8100
现在是还没有提供者 所以这里是空的
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。