更正应用程序的类路径,以使其包含oauth2.client.registration.ClientRegistrations的单个兼容版本. [英] Correct the classpath of your application so that it contains a single, compatible version of oauth2.client.registration.ClientRegistrations

查看:109
本文介绍了更正应用程序的类路径,以使其包含oauth2.client.registration.ClientRegistrations的单个兼容版本.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的Web应用程序本地部署在Tomcat服务器中,这是一个非常简单的Keycloak身份验证应用程序,但是即使删除了该路径中的所有本地存储库(.m2 \ repository \ org \ hibernate)之后,我也遇到了以下错误:我完成了mvn全新安装,并尝试再次重新部署

I'm trying to deploy my web app in Tomcat server locally and it's very simple Keycloak authentication app but i'm getting below error even after deleting all local repositories in this path ( .m2\repository\org\hibernate ) Then I done mvn clean install and tried to re-deploy again

错误消息:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getBuilderFromIssuerIfPossible(OAuth2ClientPropertiesRegistrationAdapter.java:83)

The following method did not exist:

    org.springframework.security.oauth2.client.registration.ClientRegistrations.fromIssuerLocation(Ljava/lang/String;)Lorg/springframework/security/oauth2/client/registration/ClientRegistration$Builder;

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.security.oauth2.client.registration.ClientRegistrations

这是我的代码:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .anyRequest().authenticated()
                    .and()
                    .oauth2Login();
        }
}

更新的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.baeldung.keycloak</groupId>
    <artifactId>E-Services-Portal</artifactId>
    <packaging>war</packaging>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>


    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.keycloak.bom</groupId>
                <artifactId>keycloak-adapter-bom</artifactId>
                <version>3.3.0.Final</version>
                <type>pom</type>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</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-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-client</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>

            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.glassfish.web</groupId>
                <artifactId>el-impl</artifactId>
                <version>2.2</version>
            </dependency>
            <dependency>
                <groupId>org.axonframework</groupId>
                <artifactId>axon-spring-boot-starter</artifactId>
                <version>3.4</version>
            </dependency>
        </dependencies>


    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Plugin Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
        </repository>

    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

注意:我正在使用Spring 2.2.2

推荐答案

您有一些重复的依赖项,并且正在将旧的Spring Security OAuth项目与新的Spring Security 5 OAuth支持混在一起.首先删除所有与安全性有关的工件:

You have some duplicate dependencies and you're mixing up the old Spring Security OAuth project with the new Spring Security 5 OAuth support. Start by removing all security-related artifacts:

  • spring-boot-starter-oauth2-client
  • spring-security-config
  • spring-security-oauth2
  • spring-security-oauth2-autoconfigure
  • spring-security-core

添加:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

这将带来正确版本的spring-security-core和spring-security-config以及其他依赖项.

This will bring in the correct versions of spring-security-core and spring-security-config, among other dependencies.

还添加:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-client</artifactId>
</dependency>

这篇关于更正应用程序的类路径,以使其包含oauth2.client.registration.ClientRegistrations的单个兼容版本.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆