A
A
artshelom2017-03-31 21:16:42
MongoDB
artshelom, 2017-03-31 21:16:42

Mongodb not working in spring, how to fix??

ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
        MongoOperations mongoOperation = (MongoOperations)ctx.getBean("mongoTemplate");
        mongoOperation.save(new User("Name"));

@Configuration
public class SpringMongoConfig extends AbstractMongoConfiguration {

    @Override
    public String getDatabaseName() {
        return "yourdb";
    }

    @Override
    @Bean
    public com.mongodb.Mongo mongo() throws Exception {
        return new MongoClient("127.0.0.1");
    }
}

If I run the project with this code, I get this error:
HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;

If you remove the save method, everything will work. I can't figure out what's wrong. Help.
Database created, collection not created.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kosarev, 2017-04-01
@artshelom

Judging by the error, your problem is using dependencies that are incompatible with each other. The specified method appeared in Spring Core version 4.2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question