【发布时间】:2018-04-10 12:52:24
【问题描述】:
在我将spring-security-oauth2 添加到我的 pom.xml 之后:
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
我开始明白了
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.context.logging.ClasspathLoggingApplicationListener
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:439)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:418)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:409)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:268)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:247)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233)
在运行我的@SpringBootApplication 之后。请注意,我使用的是 Spring Boot 2.0.0.M5,我认为这可能是问题的根源(w.r.t. 版本)。
这是我正在使用的整个 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>server</artifactId>
<groupId>mahlzeit</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<properties>
<spring.boot.version>2.0.0.M5</spring.boot.version>
</properties>
<dependencies>
<!-- Spring Framework Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<!-- Spring Framework -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1208-jdbc42-atlassian-hosted</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<!-- Required since this is currently using Spring RC version -->
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
我怀疑这可能与版本冲突有关 - stackoverflow 上的大多数答案都是这样 - 但我无法弄清楚我在这里遇到的实际问题。
release notes 用于 Spring Boot 2.0.0.M5 状态:
OAuth 2.0 支持
Spring Security OAuth 项目的功能正在迁移到核心 Spring Security。已添加 OAuth 2.0 客户端支持,并将适时迁移其他功能。
如果您依赖尚未迁移的 Spring Security OAuth 功能,则需要添加org.springframework.security.oauth:spring-security-oauth2并手动配置。如果您只需要 OAuth 2.0 客户端支持,您可以使用 Spring Boot 2.0 提供的自动配置。我们还将继续支持 Spring Boot 1.5,以便较旧的应用程序可以继续使用它,直到提供升级路径。
【问题讨论】:
-
你的 spring boot 设置代码在哪里?把它们也放上去。
-
我的意思是你的
autoconfiguration。你的父标签在哪里?请填写完整的pom.xml。 -
我在你的 pom.xml 中没有看到任何包装信息。我的构建插件看起来像 pastebin.com/Ghcd7tWa
-
@AtaurRahmanMunna 好吧,我把它归结为
spring-security-oauth2- 因此我相应地更新了我的问题。似乎添加此依赖项会导致此问题,我不明白为什么。我需要像TokenStore和JwtAccessTokenConverter这样的类来确保访问令牌的安全性,但很好.. 它不以该依赖项运行。 -
不幸的是,该示例不起作用。 pom缺少几个版本,Boot的Maven插件配置不完整。
标签: spring spring-boot spring-security spring-security-oauth2