确保Eureka Server连接异常。 com.sun.jersey.api.client.ClientHandlerException

时间:2018-11-20 04:25:45

标签: spring spring-security netflix-eureka configserver

在投入生产之前,我在保护Eureka和我的Config服务器方面遇到问题。这是一个相当基本的系统,应该可以运行,但是Eureka在运行后引发异常。它仅在启用Spring Boot Security时显示,但在没有它的情况下运行良好。 com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)

这是我的配置文件:

ConfigServer application.yml

server:
port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/starrynights89/spring-social-config-server
security:
  user:
    name: user
    password: password

Eureka的bootstrap.yml

spring:
  application:
    name: eureka
cloud:
  config:
    label: session
    password: password

Eureka application.yml

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://user:password@${eureka.instance.hostname}:${server.port}/eureka/

ConfigServer.java

package com.alexander.springsocial;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@SpringBootApplication
@EnableConfigServer
public class SpringSocialConfigServer {

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

@Bean
UserDetailsService userDetailsService() {
    return new InMemoryUserDetailsManager(
            User.withDefaultPasswordEncoder()
            .username("user")
            .password("password")
            .roles("USER").build());
}
}

EurekaServer.java

package com.alexander.springsocial;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@SpringBootApplication
@EnableEurekaServer
public class SpringSocialEurekaServerApplication {

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

@Bean
UserDetailsService userDetailsService() {
    return new InMemoryUserDetailsManager(
            User.withDefaultPasswordEncoder()
            .username("user")
            .password("password")
            .roles("USER").build());
}

@Configuration
protected static class SecurityPolicy extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .httpBasic()
                .and()
                .csrf().disable();
    }
}
}

另一个奇怪的方面是,即使.yml文件指定了端口8761,Eureka服务器仍在端口8080上运行:

bug

任何帮助或指点将不胜感激!

0 个答案:

没有答案