Connecting to MongoDB 3.0 with Java Spring

后端 未结 5 1344
一向
一向 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:49

    using this versions in your pom:

    
    
        org.mongodb
        mongo-java-driver
        3.2.1
    
    
    
    
        org.springframework.data
        spring-data-mongodb
        1.8.2.RELEASE
    
    

    And this configuration in spring:

        
    
    
    
        
        
        
            
                
            
        
        
    
        
                
                
        
    
        
        
        
            
                
            
        
        
    
        
                
                
                
                
        
    
        
        
                
                
        
    
        
        
            
            
        
    
        
        
            
        
    
        
            
            
            
                
                    classpath:log4j/log4j_test.properties
                
            
        
    
     
    

    With this configuration you only have to inject the MongoTemplate:

       @Autowired
       @Qualifier("mongoTemplateID")
       private MongoTemplate mongoTemplate;
    

    This should work fine =)

提交回复
热议问题