maven “启动Sping Boot 应用程序时出错”,仅当尝试“docker-compose up”时,关于spring-security-oauth2-authorization-server

yyyllmsg  于 2023-06-21  发布在  Maven
关注(0)|答案(1)|浏览(212)

我在尝试使用Sping Boot 应用程序执行docker-compose up时遇到错误。错误消息指示试图调用不存在的方法。然而,存在方法deviceAuthorizationEndpoint。我能够通过浏览IntelliJ中的外部库来定位它,并实际看到它的内容。
奇怪的是,应用程序启动时没有任何问题,当我运行它。
尝试遵循this教程
这是我的整个过程:
./mvnw clean package -DskipTests
在src/main/docker中创建Dockerfile,并将我的jar复制到同一个文件夹中:
FROM openjdk:17-oracle ARG JAR_FILE=*.jar COPY ${JAR_FILE} application.jar ENTRYPOINT ["java", "-jar", "application.jar"]
docker-compose.yml:

version: '2'

services:
  app:
    image: 'docker-spring-boot-postgres:latest'
    build:
      context: .
    container_name: app
    depends_on:
      - db
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
      - SPRING_DATASOURCE_USERNAME=compose-postgres
      - SPRING_DATASOURCE_PASSWORD=compose-postgres
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update

  db:
    image: 'postgres:13.1-alpine'
    container_name: db
    environment:
      - POSTGRES_USER=compose-postgres
      - POSTGRES_PASSWORD=compose-postgres

当我执行docker-compose up时,我得到错误:

app  | 
app  | ***************************
app  | APPLICATION FAILED TO START
app  | ***************************
app  | 
app  | Description:
app  | 
app  | An attempt was made to call a method that does not exist. The attempt was made from the following location:
app  | 
app  |     org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerPropertiesMapper.asAuthorizationServerSettings(OAuth2Authorizat
ionServerPropertiesMapper.java:56)
app  | 
app  | The following method did not exist:
app  | 
app  |     'org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder org.springframework.security.oauth2.server.authorizatio
n.settings.AuthorizationServerSettings$Builder.deviceAuthorizationEndpoint(java.lang.String)'
app  | 
app  | The calling method's class, org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerPropertiesMapper, was loaded from the f
ollowing location:
app  | 
app  |     jar:file:/application.jar!/BOOT-INF/lib/spring-boot-autoconfigure-3.1.0.jar!/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2Autho
rizationServerPropertiesMapper.class
app  | 
app  | The called method's class, org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder, is available from the following 
app  |
app  |
app  | Action:
app  |
app  | Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.security.oauth2.server.ser
vlet.OAuth2AuthorizationServerPropertiesMapper and org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder
app  |
app exited with code 1

我尝试了mvn clean install和在IntelliJ中使缓存无效,尝试仔细检查我是否拥有所有依赖项的最新版本,没有任何帮助,问题仍然存在。我使用的是Sping Boot 版本3.1.0,spring-security-oauth2-authorization-server版本1.1.0。
下面是我的完整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>3.1.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.online-shop</groupId>
    <artifactId>OnlineShop</artifactId>
    <version>1.1.0</version>
    <name>OnlineShop</name>
    <description>Online shop project</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <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.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-authorization-server</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.5.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.7.0</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit -->
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>3.0.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-messaging -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
            <version>6.0.9</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

会是什么问题呢?
任何关于解决这个问题的见解或建议将不胜感激。谢谢你!

wfypjpf4

wfypjpf41#

在修复我的pom.xml之后,我尝试了很多事情,包括尝试早期的Sping Boot 版本,不同的JDK,删除本地maven存储库和缓存,没有任何帮助。
最后我在另一台机器上试了试,它起作用了。所以,是的,这就是解决方案。显然,旧版本的依赖关系仍然在我的本地磁盘上的某个地方。

相关问题