无法让Oauth2在最新版本的Spring启动中运行

时间:2017-03-30 10:14:02

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

我正在尝试使用最新的Spring引导版本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

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

3 个答案:

答案 0 :(得分:0)

需要添加以下依赖项

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

tutorial错了。它提到的两种方式是获取spring boot应用程序以生成错误的pom.xml。

在我添加了上述执行器依赖之后,事情变得很好。

答案 1 :(得分:0)

将以下依赖项添加到pom.xml:

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

答案 2 :(得分:0)

<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>