The Spring Data MongoDB project provides integration with the MongoDB document database.
The maven dependencies:
Activating Spring Data repository support using Java Config:
Note: Do not use
Here is a basic example of using the save operation and retrieving its contents.
The maven dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
Activating Spring Data repository support using Java Config:
import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.WriteConcern;
@Configuration
@ComponentScan
@EnableMongoRepositories
public class Application extends AbstractMongoConfiguration{
@Override
protected String getDatabaseName() {
return "tuto";
}
@Override
public Mongo mongo() throws Exception {
ServerAddress serverAdress = new ServerAddress("localhost", 27017); MongoCredential credential = MongoCredential.createMongoCRCredential("moez","tuto","secret".toCharArray());
//Do not use new Mongo(), is deprecated.
Mongo mongo = new MongoClient(serverAdress,Arrays.asList(credential));
mongo.setWriteConcern(WriteConcern.SAFE);
return mongo;
}
@Override
@Bean(name="template")
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongo(), getDatabaseName());
}
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.WriteConcern;
@Configuration
@ComponentScan
@EnableMongoRepositories
public class Application extends AbstractMongoConfiguration{
@Override
protected String getDatabaseName() {
return "tuto";
}
@Override
public Mongo mongo() throws Exception {
ServerAddress serverAdress = new ServerAddress("localhost", 27017); MongoCredential credential = MongoCredential.createMongoCRCredential("moez","tuto","secret".toCharArray());
//Do not use new Mongo(), is deprecated.
Mongo mongo = new MongoClient(serverAdress,Arrays.asList(credential));
mongo.setWriteConcern(WriteConcern.SAFE);
return mongo;
}
@Override
@Bean(name="template")
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongo(), getDatabaseName());
}
}
Note: Do not use
new Mongo()because is deprecated.
Here is a basic example of using the save operation and retrieving its contents.
import static org.springframework.data.mongodb.core.query.Criteria.where; import static org.springframework.data.mongodb.core.query.Criteria.query; … Person p = new Person("Bob", 33); mongoTemplate.insert(p); Person qp = mongoTemplate.findOne(query(where("age").is(33)), Person.class);
smm panel
ReplyDeleteSmm panel
İs İlanlari
instagram takipçi satın al
HIRDAVATÇI
HTTPS://WWW.BEYAZESYATEKNİKSERVİSİ.COM.TR
servis
Jeton hile
tuzla alarko carrier klima servisi
ReplyDeletetuzla vestel klima servisi
maltepe vestel klima servisi
kadıköy vestel klima servisi
maltepe bosch klima servisi
kadıköy bosch klima servisi
maltepe arçelik klima servisi
kadıköy arçelik klima servisi
kartal samsung klima servisi
uc satın al
ReplyDeletelisans satın al
en son çıkan perde modelleri
nft nasıl alınır
yurtdışı kargo
minecraft premium
en son çıkan perde modelleri
özel ambulans