Connecting to MongoDB 3.0 with Java Spring

后端 未结 5 1335
一向
一向 2020-12-08 08:51

I am having problems in using Spring to access MongoDB with credentials. While without credentials it works like a charme, using them just fails saying

    F         


        
5条回答
  •  既然无缘
    2020-12-08 09:37

    Here is xml version to connect MongoDB 3.0.7 with Spring (parameters are passed from a property file):

    
    
    
        
    
    
    
        
        
    
    

    Then in Java, you get mongoTemplate like this:

        @Autowired
    MongoTemplate mongoTemplate;
    
    public String mongoTest() {
    
        DBCollection dc = mongoTemplate.getCollection("yourCollection");
    
        logger.debug("--get collection name=" + dc.getFullName());
    
    }
    

提交回复
热议问题