【问题标题】:No converter found capable of converting from type com.mongodb.BasicDBObject to type org.springframework.security.oauth2.provider.OAuth2Authenticatio没有找到能够从 com.mongodb.BasicDBObject 类型转换为 org.springframework.security.oauth2.provider.OAuth2Authenticatio 类型的转换器
【发布时间】:2020-10-30 06:34:36
【问题描述】:

我正在使用以下内容并使用以下库:

弹簧启动:1.5.4

spring-security - 3.2.7

spring-oauth:2.0.7

spring-boot-starter-data-mongodb : 1.5.4

spring-data-mongodb : 1.10.4

当我尝试使用此 POST url 获取 oauthtoken 时: http://localhost:8080/oauth/token?grant_type=password&username=abc&password=xyz&client_id=testing&client_secret=testing using postman 我得到这个错误:

 {
"error": "server_error",
"error_description": "No converter found capable of converting from type [com.mongodb.BasicDBObject] to type [org.springframework.security.oauth2.provider.OAuth2Authentication]"
}

请帮忙

问候

克里斯

【问题讨论】:

    标签: spring-boot spring-security spring-data-mongodb spring-oauth2


    【解决方案1】:

    我需要提供一个从 DBObject 到 OAuth2Authentication 的转换器,我参考了这个链接Set MongoDb converter programmatically 以编程方式注册转换器

    MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory, context);
    converter.setTypeMapper(mapper);
    converter.setCustomConversions(new CustomConversions(
        Arrays.asList(
                new TimeZoneReadConverter(),
                new TimeZoneWriteConverter()
        )
     ));
    converter.afterPropertiesSet();
    MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);
    

    这个链接 Spring MongoDB mapping OAuth2Authentication 将 DBObject 转换为 OAuth2Authentication,我解决了这个问题。

    问候

    克里斯

    【讨论】:

      猜你喜欢
      • 2018-02-15
      • 2020-11-19
      • 1970-01-01
      • 2019-10-20
      • 2019-02-10
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多