java - 添加 spring-security-oauth2-client 依赖项时出现“无法执行目标...,无法执行 java”错误
问题描述
当我将以下依赖项添加到我的项目时:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
clean spring-boot:run -Pdev
使用intellij idea运行项目时出现此错误:
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.1.RELEASE:run (default-cli) on project webapp: Could not exec java
我在日志中也有这个警告:
[WARNING] Could not transfer metadata net.minidev:json-smart/maven-metadata.xml from/to spring-milestones (https://repo.spring.io/libs-milestone): Authentication failed for https://repo.spring.io/libs-milestone/net/minidev/json-smart/maven-metadata.xml 401 Unauthorized
解决方案
你需要使用starters,否则你可能会缺少依赖和意外异常
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
这是完整的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.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
推荐阅读
- c# - 问答游戏 - 如何在不重复的情况下提出 6 个随机问题?
- angular - 如何获取每个组件或页面留下的所有未完成订阅的计数?
- .net - 在字符串中查找文本
- python - 使用 Tkinter 时如何并行化方法
- gcc - 手动构建的 GCC 和 Clang;Clang 查看系统 C++ 路径,而不是我的 GCC 的
- ocaml - OCaml 的 rectype 推断
- javascript - Casperjs 使登录会话保持活动状态
- python - Django 在使用 python 的旧样式字符串格式时无法处理 sql 中的 % 符号
- python - 使用 os.system 从另一个文件更改命令行值
- python - How to return an existing ir.actions.act_window from Python in Odoo 10?