Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I have a small standard Spring Boot microservice which is Spring Data REST for a single Mongo DB collection. The document contains the UUID field. The collection is a capped collection due to requirements.
Now I can build and run the app locally on my machine, no problem with that. However, we run everything in Docker on production. The container with the service is built without any issues, but once it starts, there is the following error:
{"timestamp":"2023-01-13T15:10:01.592Z","message":"Servlet.service()
for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is
org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [org.bson.types.Binary]
to type [java.util.UUID]] with root cause",
"component":"org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]",
"level":"ERROR","stack_trace":
"org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [org.bson.types.Binary]
to type [java.util.UUID]
at org.springframework.core.convert.support.GenericConversionService
.handleConverterNotFound(GenericConversionService.java:322)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter
.doConvert(MappingMongoConverter.java:1826)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository
.findAll(SimpleMongoRepository.java:444)
I have several questions actually:
Basically, how to handle it? Is it possible to handle using Spring configs?
Why SimpleMongoRepository.findAll() is called during the application start?
We have several applications with Mongo DB - they are good. What's wrong with Spring Data REST in this respect?
Why is the build OK, but when the container starts it fails?
Code samples are on Groovy just like the service (everything is public by default).
The repository is described as the following
@RepositoryRestResource( collectionResourceRel = 'events', path = 'events' )
interface EventRepository extends MongoRepository<EventMessage, String> { }
The collection configuration is the following
class CustomApplicationRunner implements ApplicationRunner {
@Autowired
MongoTemplate mongoTemplate
@Autowired
ApplicationProperties configuration
@Override
void run(ApplicationArguments args) throws Exception {
mongoTemplate.writeResultChecking = WriteResultChecking.EXCEPTION
if ( !mongoTemplate.collectionExists( EventMessage ) ) {
mongoTemplate.createCollection(EventMessage, new CollectionOptions(
configuration.mongoCollectionMaxSizeBytes,
configuration.mongoCollectionMaxDocuments,
configuration.mongoCappedCollection )
In application.yml the mongo configs are (on the development side)
mongodb:
uri: mongodb://mongodb:27017/development
auto-index-creation: true
uuid-representation: STANDARD
authentication-database: admin
The Spring Boot dependencies are
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Versions: SpringBoot 2.7.7, Groovy 4.0.6
Now I did a little research.
Here is the JIRA issue for Mongo DB driver to support to/from UUID conversion for both Binary and BsonBinary. However, only BsonBinary is updated, apparently it is not used.
Here is Spring Data MongoDB issue for the same problem (or very close to mine). The author provided the solution, but I wonder if it is the only way. I'd like to reach the author for more details, but they have been inactive since then.
I can implement the solution from the above, but I'd like to figure out what's exactly is going on.
Thank you all in advance!
Working further on the problem I accidentally found a solution.
There was Spring Boot Starter Spring Integration dependency. However, nothing really from Spring Integration was used in the service.
There was also Jackson2JsonObjectMapper bean defined which wasn't used anywhere as well. Likely it was a leftover from the early stages of the service. Here I should note that the data class in question was annotated by @JsonDeserializer with the specific deserializer class which worked correct.
So removing of the bean and the Spring Integration dependency resulted in resolving the issue.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.