JAVA-4012: Moved 1 article from spring-data-mongodb to
spring-boot-persistence-mongodb
This commit is contained in:
parent
27dfd5ca5a
commit
0fe1563388
|
@ -4,3 +4,5 @@
|
|||
- [Spring Boot Integration Testing with Embedded MongoDB](http://www.baeldung.com/spring-boot-embedded-mongodb)
|
||||
- [Upload and Retrieve Files Using MongoDB and Spring Boot](https://www.baeldung.com/spring-boot-mongodb-upload-file)
|
||||
- [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs)
|
||||
- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime)
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.baeldung.zoneddatetime.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
|
||||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
import com.baeldung.zoneddatetime.converter.ZonedDateTimeReadConverter;
|
||||
import com.baeldung.zoneddatetime.converter.ZonedDateTimeWriteConverter;
|
||||
import com.mongodb.ConnectionString;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories(basePackages = { "com.baeldung" })
|
||||
public class MongoConfig extends AbstractMongoClientConfiguration {
|
||||
|
||||
private final List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
|
||||
|
||||
@Override
|
||||
protected String getDatabaseName() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
final ConnectionString connectionString = new ConnectionString("mongodb://localhost:27017/test");
|
||||
final MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
|
||||
.applyConnectionString(connectionString)
|
||||
.build();
|
||||
return MongoClients.create(mongoClientSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getMappingBasePackages() {
|
||||
return Collections.singleton("com.baeldung");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoCustomConversions customConversions() {
|
||||
converters.add(new ZonedDateTimeReadConverter());
|
||||
converters.add(new ZonedDateTimeWriteConverter());
|
||||
return new MongoCustomConversions(converters);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package converter;
|
||||
package com.baeldung.zoneddatetime.converter;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package converter;
|
||||
package com.baeldung.zoneddatetime.converter;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.model;
|
||||
package com.baeldung.zoneddatetime.model;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.repository;
|
||||
package com.baeldung.zoneddatetime.repository;
|
||||
|
||||
import com.baeldung.model.Action;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
import com.baeldung.zoneddatetime.model.Action;
|
||||
|
||||
public interface ActionRepository extends MongoRepository<Action, String> { }
|
|
@ -1,7 +1,5 @@
|
|||
package com.baeldung.repository;
|
||||
package com.baeldung.zoneddatetime;
|
||||
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.Action;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -12,6 +10,10 @@ import org.springframework.data.mongodb.core.MongoOperations;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.baeldung.zoneddatetime.config.MongoConfig;
|
||||
import com.baeldung.zoneddatetime.model.Action;
|
||||
import com.baeldung.zoneddatetime.repository.ActionRepository;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
|
@ -9,9 +9,8 @@
|
|||
- [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb)
|
||||
- [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial)
|
||||
- [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations)
|
||||
- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions )
|
||||
- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime)
|
||||
|
||||
- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations)
|
||||
- [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions)
|
||||
|
||||
## Spring Data MongoDB Live Testing
|
||||
|
||||
|
|
|
@ -25,9 +25,6 @@ import com.mongodb.MongoClientSettings;
|
|||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
|
||||
import converter.ZonedDateTimeReadConverter;
|
||||
import converter.ZonedDateTimeWriteConverter;
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories(basePackages = "com.baeldung.repository")
|
||||
public class MongoConfig extends AbstractMongoClientConfiguration {
|
||||
|
@ -69,8 +66,6 @@ public class MongoConfig extends AbstractMongoClientConfiguration {
|
|||
@Override
|
||||
public MongoCustomConversions customConversions() {
|
||||
converters.add(new UserWriterConverter());
|
||||
converters.add(new ZonedDateTimeReadConverter());
|
||||
converters.add(new ZonedDateTimeWriteConverter());
|
||||
return new MongoCustomConversions(converters);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue