Spring Redis deserialize fails on immutable property - java

I just updated from version 2.0.X of Spring Boot to version 2.1.X. I use Spring Redis for in memory storage, and one of the objects that I store in memory has a java.util.concurrent.locks.ReentrantLock. In version 2.0.X of Spring Boot, the object deserializes successfully. In version 2.1.X, the object fails to deserialize with the exception:
org.springframework.data.keyvalue.core.UncategorizedKeyValueException: Cannot set immutable property java.util.concurrent.locks.ReentrantLock.sync!; nested exception is java.lang.UnsupportedOperationException: Cannot set immutable property java.util.concurrent.locks.ReentrantLock.sync
The problem occurs at org.springframework.data.mapping.model.BeanWrapper:85.
As this is a serializable object, I should be able to store it in Redis as is. Is this a bug in Spring? Is there a workaround?
Until this is resolved, I cannot update my Spring Boot version, and therefore my Java version. Any help would be appreciated.

Related

Spring Boot upgrade causing OAuth exception

Currently, I am working on upgrading Java and Spring Boot version for my application from Java 8 to Java 17 and then Spring Boot to 2.7.4.
With this upgrade, application started giving below exception while setting the access token.
I am passing the access token related information to another JAR which then retrieves the token information from token master.
Same configuration file worked with Java 8 and I am sure it is not corrupted. When I debug, I observed that Spring Boot is not able to parse ASCII space which was somehow handled in previous versions. Have anyone faced similar issue?
java.lang.IllegalArgumentException: scope "audience:server:client_id:ADD_00000 AAA:drr:BADAM.SS_" contains invalid characters
at org.springframework.util.Assert.isTrue(Assert.java:121)
at org.springframework.security.oauth2.client.registration.ClientRegistration$Builder.validateScopes(ClientRegistration.java:706)
at org.springframework.security.oauth2.client.registration.ClientRegistration$Builder.build(ClientRegistration.java:625)
at com.restclient.oauth2.SpringSecurityRequestInterceptor.createClientRegistration(SpringSecurityRequestInterceptor.java:165)
at com.restclient.oauth2.SpringSecurityRequestInterceptor.<init>(SpringSecurityRequestInterceptor.java:59)
at com.restclient.oauth2.OAuth2RequestInterceptor.<init>(OAuth2RequestInterceptor.java:38)
at com.restclient.feign.FeignRestClientBuilder.setTokenAuthentication(FeignRestClientBuilder.java:156)
at com.restclient.RestClientHolder.configureBuilder(RestClientHolder.java:275)
at com.restclient.RestClientHolder.getBuilder(RestClientHolder.java:313)
at com.restclient.RestClientHolder.getService(RestClientHolder.java:319)
at com.restclient.RestHelper.getService(RestHelper.java:34)
at com.restclient.RestHelper.getService(RestHelper.java:80)

Spring boot 2.2.4 release is not compatible with azure spring data cosmos 3.x.x

I'm working on springboot with cosmos api,So if i use #Query that is provided by azure-spring-data-cosmos library(3.x.x) with Springboot 2.5.0 able to get the results from cosmos database. But if i use the same azure-spring-data-cosmos library(3.x.x) with springboot 2.2.4 getting below exception
Field userRepository in com.example.service.UserService required a bean of type 'com.example.repository.UserRepository' that could not be found.The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:Consider defining a bean of type 'com.example.repository.UserRepository' in your configuration.
I would highly recommend using the latest azure-spring-data-cosmos SDK version 3.19.0 - https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos/CHANGELOG.md#3190-2022-03-10
Since spring boot releases one major version every 6 months, azure spring team supports last 2 versions of Spring Boot. We currently support spring boot 2.5.x and 2.6.x. You should be able to use any one of these versions of spring-boot with latest version of azure-spring-data-cosmos SDK.
The changelog points to the compatible version of spring boot which can be used with azure-spring-data-cosmos SDK.
Also, spring-boot 2.2.4 is more than 2 years old at this point of time. We don't support it anymore.
Not sure which version of cosmos you are using but cosmos change log clearly mentions that 3.5.0 has spring boot support 2.4.3 & above.
Please check if your cosmos version is 3.5.0 which might be causing this issue.
Reference link :
https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos/CHANGELOG.md#350-2021-03-11

Spring boot 1.5.4 to 2.0.4 AttributeConverter registered multiple times

I am aware of the following answer:
Hibernate 5.0.11 - AttributeConverter class registered mulitple times
But it isn't solving my problem. I'm upgrading Spring Boot from 1.5.4 to 2.0.4 and I'm getting
AttributeConverter class [class com.foo.CalculationModeConverter] registered multiple times
None of the code around converters has changed during the upgrade. Hibernate is registered at org.hibernate:hibernate-core:5.2.17.Final according to the dependencies task.
All of my converters were annotated with #Converter and entities used #Convert on properties. This seems to now cause a double registration. I removed #Converter and all is well thus far. I still want to find the documentation on when this changed.

Spring 4 with Elasticsearch 5

Is it possible to use elasticsearch server version 5 in combination with spring 4 (spring-data-elasticsearch)?
So far if I use spring-data-elasticsearch 2.x, I can load the app, but get error failed to get local cluster state.
If I include 3.x then I cannot start the app with error Initialization of bean failed; nested exception is java.lang.AbstractMethodError...
I suceeded to connect using spring boot 2.x, but this one uses all spring libraries >5 which is currently not an option for me.
For Elasticsearch 5.x you need to use Spring Data 3.x (Kay). Spring Boot 2.x uses that version, so that should work as you described it.
Taking a look at spring-data-parent there is an explicit dependency on Spring 5.x, so I don't think using Spring 4 will work; at least not without a lot of dependency wrangling. IMO the way forward will be to get to Spring 5 and then use Spring Data 3.

Exception when trying to use spring data mongo repository with Stream

I have MongoRepository extended and want to use the Stream API. As by the reference, I declared a query method:
public Stream<MyType> findByIdIn(Iterable<? extends String> myTypeIds);
However, when starting up my Spring Boot application, a PropertyNotFoundExceptionis thrown stating:
No property id found for type Stream!
My domain type derives from a supertype containing the actual id of the MongoDB object. Any ideas how to fix this?
I am using Spring Boot 1.2.0.RELEASE and Spring Data MongoDB 1.6.1.RELEASE.
Support for Stream as a return-type was added in Spring Data MongoDB version 1.7, as per the release notes:
What’s new in Spring Data MongoDB 1.7
...
Allow Stream as query method return type
Therefore, you need to update from 1.6.1.RELEASE to at least version 1.7. If you are using Maven, you could add the following dependency for the current latest version, which is 1.8.2.RELEASE:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>

Categories

Resources