建立尤里卡服务器
pom.xml
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>主应用类
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServerApplication.class, args);
}
}application.properties
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=falseeureka客户端设置
pom.xml
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>主应用类
@SpringBootApplication
@EnableEurekaClient
public class CurrencyExchangeServiceApplication {
public static void main(String[] args) {
SpringApplication.run(CurrencyExchangeServiceApplication.class, args);
}
}application.properties
server.port=8100
spring.application.name=currency-exchange-service
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761我没有在Eureka服务器仪表板(http://localhost:8761)中看到在eureka服务器注册的微服务货币交换服务。
相同
发布于 2020-02-06 09:44:13
我已经创建并测试了您的配置。以下两行在发现号(Eureka)客户端应用程序中不需要。
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true请使用以下依赖项
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>而不是
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>实际上,register-with-eureka : false正在停止向发现(Eureka)服务器注册,因此从客户端应用程序中完全删除它。
如果发现(Eureka)服务器端口不是8761,则添加以下行。对前任来说,
eureka.client.serviceUrl.defaultZone=http://localhost:9000发布于 2020-02-06 07:48:07
客户端应用程序类上的@EnableDiscoveryClient注释将修复此问题。
这个注释是首选的,并推荐使用较早的注释- @EnableEurekaClient。
@EnableEurekaClient用于Eureka服务器的旧版本。
@EnableDiscoveryClient支持所有可用的发现服务(包括旧版本的eureka服务器)
发布于 2020-02-06 07:47:58
由于您有此执行器依赖项,所以在默认情况下应该将spring安全性依赖项添加到您的项目中。此注册失败的可能原因是CSRF。使用下面的示例代码尝试禁用CSRF。
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}关于问题中的第二点,spring支持许多发现服务提供者,例如,如果您使用@EnableDiscoveryClient,它将尝试在类路径中找到精确匹配,并将其用于发现服务;另一方面,@EnableEurekaClient更特定于eureka发现服务,尝试在类路径中查找与eureka相关的依赖项。
https://stackoverflow.com/questions/60088983
复制相似问题