org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘testApplication’: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.nos.test.TestApplication$$EnhancerBySpringCGLIB$$c1828724]: Constructor threw exception; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Invalid numeric type, found: STRING; nested exception is org.bson.BsonInvalidOperationException: Invalid numeric type, found: STRING
Question request: List all the course names that appear in the STUDENT collection (distinct)
public List<String> test6_01(){
Query query = new Query();
List<Integer> list_course = mongoTemplate.findDistinct(query,"CID","student_course",Integer.class);
System.out.println(list_course);
List<String> list = new ArrayList<>();
for(Integer i:list_course){
Query query1 = new Query(Criteria.where("CID").is(i));
Course course = mongoTemplate.findOne(query1,Course.class,"course");
list.add(course.getNAME());
}
return list;
}
Org.bson.bsoninvalidoperationexception: invalid numeric type, found: String prompts me to find the wrong data type. Only when the CID found is of string type can I find the data imported in the data. The CID is automatically set to string type.
Then let’s look at the specific usage of finddistinct() in mongodb: you can re query, but you can’t sort.
The method receives 4 or 5 parameters, respectively:
1 query criteria
2 fields to be de duplicated filed
3 collection database table to be queried
4 POJO instance corresponding to collection to be queried
5 return result class (return list of filed fields to be de duplicated)
After modification:
public List<String> test6_01(){
Query query = new Query();
List<String> list_course = mongoTemplate.findDistinct(query,"CID","student_course",String.class);
System.out.println(list_course);
List<String> list = new ArrayList<>();
for(String i:list_course){
Query query1 = new Query(Criteria.where("CID").is(i));
Course course = mongoTemplate.findOne(query1,Course.class,"course");
list.add(course.getNAME());
}
return list;
}
Query results:
Read More:
- [Solved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xxx‘
- [Siolved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘webMvcObject
- Eureka Build Error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name
- JPA multiple-data source startup error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘t
- [Solved] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
- [Solved] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org
- [Solved] Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type…
- [Solved] SpringBoot Startup Error: org.springframework.beans.factory.UnsatisfiedDependencyException Error creating
- [Solved] org.springframework.beans.factory.UnsatisfiedDependencyException
- [Solved]Org.springframework.beans.factory.nosuchbeandefinitionexception error reported
- [Solved] org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class
- [Solved] Spring set xml Component Scanning error: Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException…
- [Solved] Error: (4, 52) Java: package org springframework. beans. factory. Annotation does not exist
- [Solved] Error creating bean with name ‘org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0‘:
- [Solved] Nacos Serve Local Startup Error: Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCre
- [Solved] BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘
- [Solved] org.springframework.context.ApplicationContextException: Failed to start bean ‘org.springframework.a
- [Solved] Spring Aop Error: Error creating bean with name ‘org.springframework.aop.config.internalAutoProxyCreator‘
- [Solved] Consider defining a bean of type ‘org.springframework.data.redis.core.RedisTemplate‘ in your configu
- Spring Aop error creating bean with name ‘org.springframework.aop.config.internalAutoProxyCreator