Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

MethodNotFoundException occurred while store token with redis #1230

Closed
rieonke opened this issue Nov 21, 2017 · 20 comments
Closed

MethodNotFoundException occurred while store token with redis #1230

rieonke opened this issue Nov 21, 2017 · 20 comments
Assignees
Milestone

Comments

@rieonke
Copy link

rieonke commented Nov 21, 2017

the exception was

Handling error: NestedServletException, Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.set([B[B)V

Env:

  • Spring Boot M6
  • Spring Data Redis 2.0.1.RELEASE
  • Spring Cloud Finchley.M4

Code throws which throws exception blow:
line 157 conn.set(accessKey, serializedAccessToken);

https://github.com/spring-projects/spring-security-oauth/blob/0c034e4dfac53c6f736a3d7e858bae37328e0fab/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/store/redis/RedisTokenStore.java#L154-L163

@rieonke
Copy link
Author

rieonke commented Nov 21, 2017

update:
the set(String,String) method was deprecated in spring-data-redis at version 2.0,
use RedisStringCommands#set instead,
so it should be

conn.stringCommands().set(...)

@rieonke
Copy link
Author

rieonke commented Nov 21, 2017

update
it works fine after upgrading the spring-date-redis dependency version to 2.0.1.RELEASE
and jedis to 2.9.0 BTW

@jgrandja
Copy link
Contributor

@rieonke Thanks for updating with the solution on explicitly declaring the dependencies. I'm going to close this issue.

@hardikbeladiya
Copy link

@jgrandja . This issue still happening in

org.springframework.security.oauth
spring-security-oauth2
2.2.1.RELEASE


org.springframework.data
spring-data-redis
2.0.4.RELEASE


redis.clients
jedis
2.9.0

Error : java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.set([B[B)V

@macdao
Copy link

macdao commented Mar 2, 2018

same issue as @hardikbeladiya

I believe it's because the RedisTokenStore compiled against RedisConnection with an old version ( actually spring-data-redis 1.5.0.RELEASE https://github.com/spring-projects/spring-security-oauth/blob/2.2.1.RELEASE/spring-security-oauth2/pom.xml)
A re-compile against the correct spring-data-redis will fix the issue

@rieonke a deprecated won't cause NoSuchMethodError

@RogierdeRuijter
Copy link

@jgrandja. Same problem:

org.springframework.security.oauth.boot
spring-security-oauth2-autoconfigure:
2.0.0.BUILD-SNAPSHOT'

org.springframework.data
spring-data-redis
2.0.1.RELEASE'

redis.clients
jedis
2.9.0

java.lang.NoSuchMethodError:org.springframework.data.redis.connection.RedisConnection.set([B[B)V

@macdao
Copy link

macdao commented Mar 8, 2018

append more information.

The signature of method org.springframework.data.redis.connection.RedisConnection.set changed from void set(byte[] key, byte[] value) (in spring-data-redis 1.5.0.RELEASE) to Boolean set(byte[] key, byte[] value) (since 2.0.0.RELEASE), so the NoSuchMethodError thrown.

@szmengran
Copy link

update
It works fine for me when I re-compile spring-security-oauth2 by upgrading the spring-date-redis dependency version to 2.0.5.RELEASE and jedis to 2.9.0

@sebarswee
Copy link

This issue happening in

spring-security-oauth2-autoconfigure:2.0.0.RELEASE

spring-data-redis:2.0.5.RELEASE

redis.clients:jedis:2.9.0

@jayzch
Copy link

jayzch commented Mar 15, 2018

spring-security-oauth2-autoconfigure:2.0.0.RELEASE

spring-data-redis:2.0.5.RELEASE

redis.clients:jedis:2.9.0

the same problem happened.

re-compile spring-security-oauth2 by upgrading the spring-date-redis dependency version to 2.0.5.RELEASE

@wilkinsona
Copy link
Contributor

I think this issue needs to be re-opened. As things stand org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.0.RELEASE does not work with Spring Boot 2.0 when using Redis to store tokens.

As has already been noted above, the underlying problem is that org.springframework.security.oauth:spring-security-oauth2 compiles against Spring Data Redis 1.5 whereas Boot 2.0 uses Spring Data Redis 2.0.x. The latter is not binary compatible with the former so a failure occurs at runtime:

Caused by: java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.set([B[B)V
	at org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore.storeAccessToken(RedisTokenStore.java:160) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at org.springframework.security.oauth2.provider.token.DefaultTokenServices.createAccessToken(DefaultTokenServices.java:122) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at org.springframework.security.oauth2.provider.token.AbstractTokenGranter.getAccessToken(AbstractTokenGranter.java:70) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at org.springframework.security.oauth2.provider.token.AbstractTokenGranter.grant(AbstractTokenGranter.java:65) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at org.springframework.security.oauth2.provider.CompositeTokenGranter.grant(CompositeTokenGranter.java:38) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer$4.grant(AuthorizationServerEndpointsConfigurer.java:561) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(TokenEndpoint.java:132) ~[spring-security-oauth2-2.2.1.RELEASE.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
	... 76 common frames omitted

@jgrandja
Copy link
Contributor

A fix is in process #1319

@fcjxxl
Copy link

fcjxxl commented Apr 27, 2018

Same error still exists, my pom.xml below:

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.1.RELEASE</version>
</parent>

<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth.boot/spring-security-oauth2-autoconfigure -->
<dependency>
	<groupId>org.springframework.security.oauth.boot</groupId>
	<artifactId>spring-security-oauth2-autoconfigure</artifactId>
	<version>2.0.0.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth -->
<dependency>
	<groupId>org.springframework.security.oauth</groupId>
	<artifactId>spring-security-oauth</artifactId>
	<version>2.3.2.RELEASE</version>
</dependency>

@jgrandja
Copy link
Contributor

@fcjxxl Other users have reported that it has been fixed. See #1319.
I noticed your POM uses spring-security-oauth...it should be spring-security-oauth2

@yy306525121
Copy link

yy306525121 commented Jul 13, 2018

im use spring-cloud-starter-oauth2 and spring-cloud-starter-data-redis i have this problem too,
image
i found
image
spring-security-oauth2 is 2.2.1.RELEASE, bug in 2.2.1.RELEASE the RedisTokenStore.java is
image
but after 2.3.1RELEASE is
image
so i do like this
image

@HarishKumarGudivada
Copy link

HarishKumarGudivada commented Aug 29, 2018

      <parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>1.3.8.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

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




              <dependency>
		<groupId>org.springframework.security.oauth.boot</groupId>
		<artifactId>spring-security-oauth2-autoconfigure</artifactId>
		<version>2.0.0.RELEASE</version>
	</dependency>

getting following error : java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)V

if i commented spring-security-oauth2-autoconfigure , its working fine. I am trying to use this dependency in existing project. Please , help in solving the above issue

@rwinch
Copy link
Contributor

rwinch commented Aug 31, 2018

@HarishKumarGudivada You are bringing in spring-security-oauth2-autoconfigure on a Boot 1.x project which will not work. For Boot 1.x the autoconfigure support is included in the Boot autoconfig.

PS: In the future please create questions on StackOverflow and not on GitHub (especially not on a closed issue which may not be noticed)

@fanjlii
Copy link

fanjlii commented Sep 24, 2018

That's my solution:
solution

@ddkcstream
Copy link

That's my solution:
solution

got this solution

@abccbaandy
Copy link

That's my solution:
solution

You don't need exclude spring-security-oauth2 actually. 2nd dependency will override the version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.