@Bean public CommandLineRunner runner(GitterProperties props, MongoProperties mongoProperties) { return args -> { context.registerBean(Mate.class, () -> new Mate("Lithium", "Alex", true)); Mate mate = context.getBean(Mate.class); System.out.println("Mate from context: " + mate.nickname); System.out.println("Gitter Room: " + props.getRoom()); Flux<Mate> people = Flux.just( new Mate("aliaksei-lithium", "Aliaksei"), new Mate("IRus", "Ruslan"), new Mate("bsiamionau", "Bahdan") ); repository.deleteAll().thenMany(repository.save(people)).blockLast(); }; }
public MongoInstance() throws IOException, InterruptedException { // Download Mongo artifacts into the project directory to ease cleanup IDownloadConfig downloadConfig = new DownloadConfigBuilder() .defaultsForCommand(Command.MongoD) .artifactStorePath(ARTIFACT_STORE_PATH) .build(); // Extract Mongo artifacts into the project directory to ease cleanup IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder() .defaults(Command.MongoD) .artifactStore(new ExtractedArtifactStoreBuilder() .defaults(Command.MongoD) .download(downloadConfig) .extractDir(EXTRACTED_STORE_PATH) ) .build(); // Store Mongo data into the project directory to ease cleanup Storage replication = new Storage("./data/mongodb/data", null, 0); MongodStarter starter = MongodStarter.getInstance(runtimeConfig); IMongodConfig mongodConfig = new MongodConfigBuilder() .version(Version.Main.PRODUCTION) .cmdOptions(new MongoCmdOptionsBuilder() .useNoJournal(false) .useSmallFiles(true) .build()) .net(new Net(MongoProperties.DEFAULT_PORT, Network.localhostIsIPv6())) .replication(replication) .build(); mongo = starter.prepare(mongodConfig); process = mongo.start(); }
public EmbeddedMongoAutoConfiguration(MongoProperties properties, EmbeddedMongoProperties embeddedProperties, ApplicationContext context, IRuntimeConfig runtimeConfig) { this.properties = properties; this.embeddedProperties = embeddedProperties; this.context = context; this.runtimeConfig = runtimeConfig; }
/** * Constructor from {@link MongoAutoConfiguration}. */ @Autowired public MongoDbConfiguration(MongoProperties properties, ObjectProvider<MongoClientOptions> options, Environment environment) { this.mongoProperties = properties; this.options = options.getIfAvailable(); this.environment = environment; }
private void copyMissingProperties(MongoProperties mongoProperties, MongeezProperties mongeezProperties) { if (StringUtils.isEmpty(mongeezProperties.getDatabase())) { mongeezProperties.setDatabase(mongoProperties.getMongoClientDatabase()); } if (StringUtils.isEmpty(mongeezProperties.getAuthenticationDatabase())) { mongeezProperties.setAuthenticationDatabase(mongoProperties.getAuthenticationDatabase()); } if (!mongeezProperties.hasCredentials() && hasCredentials(mongoProperties)) { // cannot copy credentials because Spring Data MongoDB clears the password after using it String msg = "Found credentials for Spring Data MongoDB but no credentials for Mongeez. " + "You need to define both for authentication to work."; throw new BeanCreationException(msg); } }
@Bean @ConditionalOnProperty(value = APPLICATION_DATA_TYPE, havingValue = APPLICATION_DATA_TYPE_MONGO) @Autowired public MongoTemplate mongoTemplate(MongoProperties properties, @Value("${spring.data.mongodb.password}") String password) throws Exception { MongoClient client = new MongoClient(new ServerAddress( properties.getHost(), properties.getPort())); MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(client, properties.getDatabase(), new UserCredentials(properties.getUsername(), password)); return new MongoTemplate(mongoDbFactory); }
@Autowired public MongoConfiguration(MongoProperties mongoProperties) { this.mongoProperties = mongoProperties; }
public MongoProperties getNaive() { return naive; }
public void setNaive(MongoProperties naive) { this.naive = naive; }
public MongoProperties getComplete() { return complete; }
public void setComplete(MongoProperties complete) { this.complete = complete; }
private int getPort() { if (this.properties.getPort() == null) { return MongoProperties.DEFAULT_PORT; } return this.properties.getPort(); }
public MongoDataAutoConfiguration(ApplicationContext applicationContext, MongoProperties properties) { this.applicationContext = applicationContext; this.properties = properties; }
GridFsMongoDbFactory(MongoDbFactory mongoDbFactory, MongoProperties properties) { Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null"); Assert.notNull(properties, "Properties must not be null"); this.mongoDbFactory = mongoDbFactory; this.properties = properties; }
public MongoDataAutoConfiguration(MongoProperties properties, Environment environment, ResourceLoader resourceLoader) { this.properties = properties; this.environment = environment; this.resourceLoader = resourceLoader; }
private boolean hasCredentials(MongoProperties properties) { return properties.getUsername() != null && properties.getPassword() != null; }
@Before public void beforeEachTest() { CodecRegistry codecRegistry = CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(new LocalDateTimeCodec(), new HostAndPortCodec(), new LocalDateTimeCodec())); MongoProperties properties = new MongoProperties(); MongoClient mongoClient = new MongoClient(new MongoClientURI(properties.getUri(), MongoClientOptions.builder().codecRegistry(codecRegistry))); mongoMetricsRepository = new MongoMetricsRepository(mongoClient, properties, new ObjectMapper()); mongoMetricsRepository.init(); metricsService = new MetricsService(mongoMetricsRepository); }
@Before public void beforeEachTest() { CodecRegistry codecRegistry = CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(new LocalDateTimeCodec(), new HostAndPortCodec(), new LocalDateTimeCodec())); MongoProperties properties = new MongoProperties(); MongoClient mongoClient = new MongoClient(new MongoClientURI(properties.getUri(), MongoClientOptions.builder().codecRegistry(codecRegistry))); mongoMetricsRepository = new MongoMetricsRepository(mongoClient, properties, new ObjectMapper()); mongoMetricsRepository.init(); }