我从这里得到了一个简单的 SSO 示例项目
目前,该示例的工作方式如下。
启动 app1、app2、sso-server。
加载http://localhost:8082/app1会重定向到 http://localhost:8080/sso-server的登录页面
用户名:用户,密码:密码
- 登录成功后会重定向回 http://localhost:8082/app1页面会显示“Welcome to app1, user”
- 现在在加载http://localhost:8083/app2页面将显示“Welcome to app2, user”,因为我们已经登录了。
现在我的问题是示例使用 spring-boot-starter-parent 版本 1.5.9.RELEASE
该示例还使用了 spring-cloud 依赖项。我读到 spring-cloud 将不支持 spring-boot-starter-parent 版本 2 或更高版本。
因此,我尝试从 app1 中删除 spring cloud 依赖项,经过一番艰难的尝试后,我可以启动应用程序。我的新pom如下。
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.shekhargulati</groupId>
<artifactId>app1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>app1</name>
<description>App1</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
</dependencies>
现在在加载 app1 时,它将显示 sso 登录窗口。但是登录成功后会抛出404错误。
如果我在 sso-server 应用程序中进行相同的更改,授权将不起作用。授权 API 将抛出 404。
请帮我解决这个问题。 我的需要是,让这个应用程序像以前一样使用 spring boot starter parent version 2+ 工作。