新建spring boot项目,修改pom文件依赖
<!--导入spring boot依赖-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.5.RELEASE</version>
<relativePath/>
</parent>
<!--导入spring cloud 依赖-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--导入eureka server 依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!--导入spring security 依赖,用于eureka登录认证-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!--导入spring boot 开发工具依赖,用于热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!--导入spring boot maven插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
配置application.yml文件
security:
basic:
enabled: true #开启安全认证
user:
name: user #eureka登录的用户名
password: password123 #eureka登录的密码
server:
port: 8761 #eureka链接的端口
eureka:
client:
service-url:
defaultZone: http://user:password123@localhost:8761/eureka #注册到eureka的地址 #http://localhost:8761/eureka
register-with-eureka: false #不要把自身注册到eureka 不要把自身单作eureka client 用于单机环境
fetch-registry: false #不要获取注册表
spring boot启动类添加如下注解:
@SpringBootApplication //spring boot应用注解
@EnableEurekaServer //启动eurakaServer,标明该应用为eurekaServer
启动应用,启动成功后在地址栏输入:http://localhost:8761/,看到eureka的界面即可。