Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 与Eureka客户之间的沟通_Spring Boot_Client_Netflix Eureka - Fatal编程技术网

Spring boot 与Eureka客户之间的沟通

Spring boot 与Eureka客户之间的沟通,spring-boot,client,netflix-eureka,Spring Boot,Client,Netflix Eureka,我有两个客户机注册到同一台Eureka服务器,当我检查服务器UI时,我看到两个客户机都注册良好。但是当我试图从另一个客户端调用一个客户端时,我得到了IO异常:ResponseEntity quoteResponse=restTemplate.exchangehttp://lirs-security/api/userSecurity/validateUserToken/ +令牌,HttpMethod.GET, null,新的ParameteredTypeReference{ }; /**Respo

我有两个客户机注册到同一台Eureka服务器,当我检查服务器UI时,我看到两个客户机都注册良好。但是当我试图从另一个客户端调用一个客户端时,我得到了IO异常:ResponseEntity quoteResponse=restTemplate.exchangehttp://lirs-security/api/userSecurity/validateUserToken/ +令牌,HttpMethod.GET, null,新的ParameteredTypeReference{ }; /**ResponseEntity quoteResponse=restTemplate.exchangehttp://localhost:8103/api/userSecurity/validateUserToken/ +令牌,HttpMethod.GET, null,新的ParameteredTypeReference{ }; */ . 当我直接访问其他服务时,它会工作。错误:org.springframework.web.client.ResourceAccessException:GET请求的I/O错误http://lirs-security/cbf69488-5624-4181-9254-ff423afa7620: 里尔安全;嵌套异常是java.net.UnknownHostException:lirs安全性 这就是我的控制台的外观: 我已经为此奋斗了好几天,但我已经没有主意了。在这一点上,我真的需要所有能得到的帮助

`#Server application.yml file
spring:
application:
name: lirs-gateway

server:
port: 8101
eureka:
instance:
hostname: localhost 
client:
registerWithEureka: false
fetchRegistry: false
#server:
#waitTimeInMsWhenSyncEmpty: 0
serverUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

#security client yml file
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8101/eureka/
instance:
hostname: localhost

#Security client properties file
spring.application.name=lirs-security
server.port=8103

spring.datasource.url=jdbc:mysql://localhost:3306/***** 
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.naming- 
strategy=org.hibernate.cfg.ImprovedNamingStrategy 

#tax payers client yml
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8101/eureka/
instance:
hostname: localhost

# client properties file
spring.application.name=tax-payers
server.port=8102

spring.datasource.url=jdbc:mysql://localhost:3306/****
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.naming- 
strategy=org.hibernate.cfg.ImprovedNamingStrategy
security.oauth2.client.clientId=myID
security.oauth2.client.scope=bigScope
simpleProp=this is the value`

`@EnableDiscoveryClient
//@EnableEurekaClient
@SpringBootApplication
public class TaxpayersApplication {

public static void main(String[] args) {
    SpringApplication.run(TaxpayersApplication.class, args);
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
    return source;
}


}

@EnableDiscoveryClient
//@EnableEurekaClient
@SpringBootApplication
public class LirsSecurityApplication {

public static void main(String[] args) {
    SpringApplication.run(LirsSecurityApplication.class, args);
}
}`
Eureka用于定位服务。这意味着您不应该在客户端中硬编码任何URL。两个eureka客户机集成的基本示例如下所示:

1台Eureka服务器:

spring:
  application:
    name: SERVER1
server:
  port: 8761
eureka:
  server:
    hostname: localhost
2首次申请:

spring:
  application:
    name: app_1
server:
  port: 0
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
spring:
  application:
    name: app_2
server:
  port: 0
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
3第二次申请:

spring:
  application:
    name: app_1
server:
  port: 0
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
spring:
  application:
    name: app_2
server:
  port: 0
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
我们在eureka服务器上注册了两个应用程序

现在的想法是从eureka服务器请求所需的应用程序URL并使用它

第一个应用程序代码:

@SpringBootApplication
@EnableEurekaClient
@RestController
public class ClientApp {
    public static void main(String[] args) {
        SpringApplication.run(ClientApp.class, args);
    }

    @Bean
     RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Autowired
    private EurekaClient discoveryClient;

    @RequestMapping("/greetingTest")
    public String greetingTest() {
        String url = discoveryClient.getNextServerFromEureka("APP_2", false).getHomePageUrl();
        return restTemplate().getForEntity(url + "/greeting", String.class).getBody();
    }

    @RequestMapping("/greeting")
    public String greeting() {
        return "I'm first app";
    }
}
第二个应用程序的代码相同,但此行除外:

discoveryClient.getNextServerFromEureka("APP_2", false)
它将使用APP_1作为服务名称。所以基本上第一个应用程序请求第二个应用程序URL,反之亦然

因此,使用/greetingTest路径调用第一个应用程序将导致-我是第二个应用程序,而使用/greetingTest路径调用第二个应用程序将导致-我是第一个应用程序,这意味着它们已成功集成


为了进一步阅读,您可以使用spring cloud。

您可以发布application.yml或application.properties吗?另外,您使用@EnableDiscoveryClientI的类也添加了上述更新