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>
Related
I'm currently working on a spring webflux project using Spring cloud sleuth dependency.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.5.1</version>
</dependency>
I'm working on a set of APIs which get a request payload that contains 3 Strings. I want to concatenate these 3 strings to use as my custom trace id. I also want to achieve the following requirement.
This custom_trace_id should be able to be added to every log. (We are getting sleuth trace id in logs by adding %X{traceId} within our log4j.xml file to print the traceId in all logs)
This custom trace id must be sent to the calls that are made by WebClient (Sleuth sets the X-B3-TraceId header to all calls made by WebClient, I want the same but using the custom_trace_id)
If possible I want to change the name of X-B3-TraceId header to a different value such as correlation-id so that if someone makes a request to our spring webflux application the sleuth should first check the correlation-id and use it as trace id. (Note: custom_trace_id = correlation-id)
Note that the spring sleuth already does the above 3 things. I want to have custom value for the trace id instead. Can someone please help or suggest something for my usecase
Spring Boot 2.5.x is not compatible with Spring Cloud Hoxton (Sleuth 2.2.x).
You need to use Spring Cloud 2020.0.x aka Ilford (Sleuth 3.0.x).
You can set spring.sleuth.propagation.type to CUSTOM and implement your own Propagation and Propagation.Factory, please see the docs: How to Change The Context Propagation Mechanism?.
This should help you achieving your goals above, however, there are some downsides. This is mostly my opinion, please feel free to ignore it and do whatever you would like to:
B3, W3C and AWS propagation types are standards with support of other projects/tooling
You are trying to create a 4th "standard" that is not supported by anything (but maybe by an internal system)
You need to add support for this custom propagation type to every new component so that they will also understand this "standard"
Sometimes it worth consider moving to a universal standard rather than using a custom one even if there is a legacy system behind it
I want to be able to use my Entities classes / documents created with Java Spring in order to create my MongoDB Database at Runtime abd see the different fields of the documents and collections and this automatically when running my spring boot application.
I use the property in my application.properties.
hibernate.ogm.datastore.create_database=true
and as a dependency in pom.xml :
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>5.4.1.Final</version>
</dependency>
The application launches but the associated database is not created, What am i missing here,
Thank you.
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.
I created a spring-boot project to read and write data to Sybase database. The project was working as intended. However, whenever I added activiti dependencies, It says "couldn't deduct database type from database product name 'Adaptive Server Enterprise'". According to my understanding, there are some classes conflicting each other in activiti and spring even though I do not use anything regarding activiti( except the fact that I just opened a folder called processes in the resources directory).
The activiti dependencies I added are:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-actuator</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-jpa</artifactId>
<version>5.21.0</version>
</dependency>
To clarify my point in this, I wanted to use activiti just for workflow purposes and leave the rest of the ETL or database job to spring. If I change database from Sybase to Mysql, the project also works fine even with activiti dependencies. As far as I know activiti has no support for Sybase and apparently, it tries to interfere everything possible and overrides something that was already working at the first place. How can I overcome this problem?
you are trying to use the spring boot starter which automatically tries to configure a database using spring autoconfiguration. Can you clarify with which database do you want to use Activiti? If you want to use Sybase you will need to contribute back to the project with Sybase support. Alternatively, you can not use the starter and depend on the engine directly, this will push you to provide the engine configurations for your spring environment. You can also check the -starter project and adapt as needed.
HTH
I am trying to read values from ldap using spring-ldap.
I am trying to follow ldap query based on the document
http://docs.spring.io/spring-ldap/docs/current/reference/#basic-queries
My program is failing to compile because LdapQuery is not found.
LdapQuery query = query()
.base("dc=261consulting,dc=com")
.attributes("cn", "sn")
.where("objectclass").is("person")
.and("sn").is(lastName);
My pom.xml has the following entry.
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
I looked at spring-ldap api documentation at http://docs.spring.io/spring-ldap/site/apidocs/index.html and they dont seem to have LdapQuery class.
Can you please help on how to read values from ldap using spring? If you can provide an example, that will be great.
Thanks
LdapQuery was added with 2.0. If you're constrained to an earlier version consider using LdapTemplate.