服务注册中心加了安全认证之后,然后我运行eureka client 。。。发现。。。。
报错了,注册不了。。。后来才发现,注册地址要改一下。。改成下面这样:
eureka:
client:
service-url:
defaultZone: http://boy:coolBoy@192.168.1.15:8000/eureka/
在地址里加上用户名密码,然后运行还是报错,是因为新版本的security默认开启csrf了,关掉就好了,新建一个配置类,看下面:
package com.yezi.dreamspark.dreamsparkserver.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable(); //关闭csrf
http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); //开启认证
}
}
然后运行,完美!!成功注册。