Я использовал весеннюю загрузку 2.2.6.RELEASE, весенняя облачная версия: Hoxton.SR3 и jdk1.8. Хорошо работает без Cloud Security. Он может войти в систему с помощью Cloud Security (URL: http://localhost: 8761 ). Но когда я закончил вход в систему, он получил ошибку. Например:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Apr 09 22:13:35 CST 2020
There was an unexpected error (type=Not Found, status=404).
No message available
Здесь есть все мои тестовые коды и моя структура каталогов: структура каталогов
pom. xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.practice</groupId>
<artifactId>eureka-security-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-security-server</name>
<description>eureka-security-server practice for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
server.port=8761
spring.application.name=eureka-security-server
spring.security.user.name=root
spring.security.user.password=root
eureka.instant.hostname=localhost
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
EurekaSecurityServerApplication. java
package com.quickread.eurekasecurityserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EurekaSecurityServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaSecurityServerApplication.class, args);
}
}
WebSecurityConfig. java
package com.quickread.eurekasecurityserver.config;
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;
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/eureka/**");
// http.csrf().disable();
super.configure(http);
}
}