Spring OAuth2 需要 PlatformTransactionManager [英] Spring OAuth2 Requiring PlatformTransactionManager

查看:62
本文介绍了Spring OAuth2 需要 PlatformTransactionManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Spring Security OAuth2 与 JWT 令牌集成到 Spring Boot 项目中.我的身份验证服务器的配置类似于此 示例项目.

I'm working on integrating Spring Security OAuth2 with JWT tokens into a Spring Boot project. My authentication server is configured similar to what is found in this sample project.

当 OAuth2 客户端在 /oauth/token 上执行 POST 时,它无法创建访问令牌.记录的具体错误是:

When the OAuth2 client performs the POST on /oauth/token it is unable to create the access token. The specific error logged is:

<代码>o.s.s.o.provider.endpoint.TokenEndpoint :处理错误:NoSuchBeanDefinitionException,未定义 [org.springframework.transaction.PlatformTransactionManager] 类型的合格 bean

我已经在调用 tokenServices.createAccessToken 时将其调试到 AbstractTokenGranter 第 70 行.我无法轻松地进一步调试,因为此调用实际上是通过代理进行的.似乎配置中的某些东西想要使这个事务性.在 JWT 中创建访问令牌不应该是事务性的.我明白为什么检索访问代码是事务性的,但代码成功地超过了那个点.

I've debugged it down to AbstractTokenGranter line 70 at the call to tokenServices.createAccessToken. I've not been able to easily debug further than that because this call actually goes through a proxy. It seems something in the configuration is wanting to make this transactional. Creating access tokens shouldn't be transactional in JWT. I could see why retrieving the access code would be transactional, but the code successfully gets past that point.

为什么这可能需要 PlatformTransactionManager,我该如何提供?

Why might this be requiring the PlatformTransactionManager and how can I supply one?

推荐答案

问题是您在应用程序中使用 new InMemoryTokenStore() 配置了内存数据库的使用,但是您的 spring-引导应用程序不包含内存数据库.

Problem is that you configured in your application a usage of a in-memory database with new InMemoryTokenStore(), but your spring-boot application contains no in-memory database.

解决方案:在您的 spring-boot pom 或 gradle 依赖项中添加内存数据库.

Solution: add in your spring-boot pom or gradle dependency a in-memory database.

H2 和 Maven pom 示例:

Example for H2 and Maven pom:

<dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.187</version>
</dependency>

这篇关于Spring OAuth2 需要 PlatformTransactionManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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