【问题标题】:Unable to get Oauth2 working in latest version of Spring boot无法让 Oauth2 在最新版本的 Spring Boot 中工作
【发布时间】:2017-08-24 04:49:54
【问题描述】:

我正在尝试使用最新的 Spring boot 版本 1.5.2.RELEASE 运行一个简单的 oauth2 应用程序。

我按照spring-boot-oauth2 的所有步骤操作,直到他们告诉您“发生了什么”,但在配置 application.yml 后,运行应用程序不起作用并出现以下错误 -

WARN 27759 [main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.opentable.DemoApplication]; nested exception is java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2SsoDefaultConfiguration due to org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake) 
ERROR 27759 [main] o.s.b.f.s.DefaultListableBeanFactory: Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3b07a0d6: startup date [Thu Mar 30 15:06:55 IST 2017]; root of context hierarchy

是否需要显式创建配置类?

【问题讨论】:

    标签: spring spring-mvc spring-boot oauth-2.0


    【解决方案1】:

    需要添加以下依赖

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

    tutorial 是错误的。上面提到的两种获取spring boot应用程序启动的方法都是生成错误的pom.xml。

    在我添加上述执行器依赖项后,一切正常。

    【讨论】:

      【解决方案2】:

      在 pom.xml 中添加如下依赖:

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

      【讨论】:

        【解决方案3】:
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
                </dependency>
        
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
        

        【讨论】:

          猜你喜欢
          • 2017-03-10
          • 1970-01-01
          • 1970-01-01
          • 2019-12-03
          • 1970-01-01
          • 2017-11-28
          • 2014-03-11
          • 2020-03-23
          • 1970-01-01
          相关资源
          最近更新 更多