java - 无法在 spring 中处理配置类的导入候选

标签 java spring rest maven spring-security-oauth2

我正在尝试运行我的 Spring MVC 应用程序,但由于某种原因,找不到 GlobalAuthenticationConfigurerAdapter

代码片段如下:

package co.uk.zohaibkhan.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;


@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

  @Override
  public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
    oauthServer.checkTokenAccess("isAuthenticated()");
  }

  @Override
  public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory().withClient("my-trusted-client")
        .authorizedGrantTypes("client_credentials", "password")
        .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT")
        .scopes("read", "write", "trust")
        .resourceIds("oauth2-resource")
        .accessTokenValiditySeconds(5000)
        .secret("secret");
  }


  @Override
  public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    super.configure(endpoints);
  }
}

和堆栈跟踪:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [co.uk.zohaibkhan.config.AuthorizationServerConfig]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
...

这是我的 pom.xml

的依赖项
<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-thymeleaf</artifactId>
</dependency>
<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <scope>runtime</scope>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
  <version>2.0.2.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security.oauth</groupId>
  <artifactId>spring-security-oauth2</artifactId>
  <version>2.0.2.RELEASE</version>
</dependency>

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

有人可以帮忙吗?构建工作正常,我在解决依赖关系时确实遇到了一些问题,但现在一切看起来都很好,但我无法弄明白。

谢谢!

最佳答案

我想通了!

因此,如果您有一个看起来不可靠的依赖项,只需将其从 Maven 中删除,然后转到错误并自动更正以查找 Maven 依赖项,然后使用反复试验并找到正确的依赖项!

如果没有显示任何类,那么继续设置然后到 maven,在那里你应该更新你的存储库

现在我的 Maven 依赖项已经改变了,如下所示:

<dependency>
  <groupId>org.springframework.security.oauth</groupId>
  <artifactId>spring-security-oauth2</artifactId>
  <version>2.3.0.BUILD-SNAPSHOT</version>
</dependency>

关于java - 无法在 spring 中处理配置类的导入候选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49341277/

相关文章:

scala - Spark Send DataFrame 作为 HTTP Post 请求的主体

java - 使用此代码从数组列表中删除重复项但忽略大小写

java - 如何从数组列表中检索值并根据所选国家/地区显示?

arrays - WordPress JSON API : Retrieve multiple posts by ids

java - Spring MVC 无法在 CloudFoundry 上运行

java - 如何使用 spring RestTemplate 生成带有二进制数据的curl 请求?

c# - 使用 HttpClient 在 localhost 上调用 rest api 导致 401 Unauthorized,IIS 8.5

java - 过多的 ImageButton 会导致应用程序崩溃

java - Gmail API : Credentials for Gmail API

Spring - 如何测试具有 ApplicationEventPublisher 依赖关系的 Controller ?