本文主要是介绍一个eureka注册中心入门例子,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.先创建eureka父工程<?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>spring-cloud-action</artifactId><groupId>com.lq.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>eureka</artifactId><packaging>pom</packaging><modules><module>eureka-server</module><!--<module>eureka-server-ha</module><module>eureka-provider</module>--></modules><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency></dependencies></project>
2.创建eureka-server子工程
<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>eureka</artifactId><groupId>com.lq.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>eureka-server</artifactId><packaging>jar</packaging><name>eureka-server</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies>
</project>
3.启动类
package com.lq.springcloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplicationpublic class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}
}
4.application.properties
spring.application.name=eureka
server.port=8761
#是否将自己注册到eureka-server 默认为true
eureka.client.registerWithEureka=false
#是否从eureka-server获取注册信息,默认为true
eureka.client.fetchRegistry=false
实际应用中要注意的是启动类默认注解扫描的路径是启动类所在包,所以不在该包的controller或service层将无法访问
这篇关于一个eureka注册中心入门例子的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!