Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource Spring Data MongoDB - Spring Web Services - Parent - SpringSource

static.springsource.org
from static.springsource.org More from this publisher
13.07.2015 Views

please define productname in your docbook file!@Configurationpublic class GeoSpatialAppConfig extends AbstractMongoConfiguration {@Beanpublic Mongo mongo() throws Exception {return new Mongo("localhost");}@Overridepublic String getDatabaseName() {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 MongoDB 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 Spring'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.Spring's MongoDB namespace enables you to easily enable mapping functionality in XML1.4.0.BUILD-SNAPSHOTSpring Data MongoDB -Reference Documentation 79

please define productname in your docbook file!>

please define productname in your docbook file!>

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

Saved successfully!

Ooh no, something went wrong!