13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

please define productname in your docbook file!@Configurationpublic class GeoSpatialAppConfig extends AbstractMongoConfiguration {@Beanpublic Mongo mongo() throws Exception {return new Mongo("localhost");}@Overridepublic String get<strong>Data</strong>baseName() {return "database";}@Overridepublic String getMappingBasePackage() {return "com.bigbank.domain";}// the following are optional@Overrideprotected void afterMappingMongoConverterCreation(MappingMongoConverter converter) {Set>();converterList.add(new org.springframework.data.mongodb.test.PersonReadConverter());converterList.add(new org.springframework.data.mongodb.test.PersonWriteConverter());converter.setCustomConverters(converterList);}@Beanpublic LoggingEventListener mappingEventsListener() {return new LoggingEventListener();}}Example 7.1 @Configuration class to configure <strong>MongoDB</strong> mapping supportAbstractMongoConfiguration requires you to implement methods that define acom.mongodb.Mongo as well as provide a database name. AbstractMongoConfigurationalso has a method you can override named 'getMappingBasePackage'which tells the converter where to scan for classes annotated with the@org.springframework.data.mongodb.core.mapping.Document annotation.You can add additional converters to the converter by overriding the methodafterMappingMongoConverterCreation. Also shown in the above example is aLoggingEventListener which logs MongoMappingEvents that are posted onto <strong>Spring</strong>'sApplicationContextEvent infrastructure.NoteAbstractMongoConfiguration will create a MongoTemplate instance and registered with thecontainer under the name 'mongoTemplate'.You can also override the method UserCredentials getUserCredentials() to provide theusername and password information to connect to the database.<strong>Spring</strong>'s <strong>MongoDB</strong> namespace enables you to easily enable mapping functionality in XML1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!