1.献上我的pom.xml
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>demo</groupId>
<artifactId>demo</artifactId>
<version>1.0.0.RELEASE</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<groupId>demo</groupId>
<artifactId>demo-eureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-eureka</name>
<description>Demo project for Eureka</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<!--依赖管理-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR3</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.yml
spring:
freemarker:
prefer-file-system-access: false
server:
port: 10016 # 将服务器端口号修改
eureka:
instance:
hostname: localhost # 表示访问的是本地
client:
register-with-eureka: false # 默认情况下,这个应用会向注册中心注册自己,设置为false表示这种默认行为
fetch-registry: false # 表示不会去检索其他服务
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
3.启动类(注意注解)
@SpringBootApplication
@EnableEurekaServer
public class DemoEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(DemoEurekaApplication.class, args);
}
}
4.启动后可以访问啦~注意访问地址不要出错
![](https://i-blog.csdnimg.cn/blog_migrate/4006b1319a437bf75e9aee3e89c324d4.png)