Closed ShimonMimoun closed 1 year ago
@ShimonMimoun You can change the server for the download to a local one: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/main/docs/Howto.md#customize-download-url
.. but as you are using spring you may apply this customization this way: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/main/HowTo.md#customize-mongod
.. feel free to ask if you struggle with anything:)
@ShimonMimoun there are more ways to customize this.. but this is maybe the easiest one.. i think i should add some documentation for this kind of problem ...
@michaelmosmann
Thank you for your response. I have already tried that, but it still tries to connect to the main Atlas server. Can you guide me on how to do this? I tried modifying the mongod builder, but I wasn't successful. Could you please enlighten me on how to accomplish this?
@ShimonMimoun can you show me some code?
@michaelmosmann
@Bean
public Mongod mongoConfiguration() {
return Mongod.builder()
.distributionBaseUrl(Start.to(DistributionBaseUrl.class)
.initializedWith(DistributionBaseUrl.of(DOWNLOAD_PATH)))
.build();
}
@Bean
public MongoClient mongoConfiguration(){
return MongoClients.create(
new MongoClientOptions.Builder()
.setDownloadUrl(DOWNLOAD_PATH)
.build());
}
@ShimonMimoun you have to use a BeanPostProcessor to do this as in https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/main/HowTo.md#customize-mongod
.. you can not define just a bean for that because things are a little bit complicated as you see here: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/374ef6bce27ce7ec8a7c889b71c4b192456db8c7/src/main/java/de/flapdoodle/embed/mongo/spring/autoconfigure/EmbeddedMongoAutoConfiguration.java#L191
I have found the solution, and I'm sharing it with you.
@Bean
BeanPostProcessor customizeMongod() {
return TypedBeanPostProcessor.applyBeforeInitialization(Mongod.class, src ->
Mongod.builder()
.from(src)
.distributionBaseUrl(
Start.to(DistributionBaseUrl.class)
.initializedWith(DistributionBaseUrl.of(DOWNLOAD_PATH))
)
.build());
}
Thanks for your help @michaelmosmann
Hello everyone,
I'm using Java 17 and Spring 3. I would like to change the download path for the MongoDB version to a different link.
Let me explain my issue. I am working in an environment where access to the external server is limited.
Previously, I used this solution, but it no longer works.
@Bean public DownloadConfigBuilderCustomizer downloadCustomizer() { DistributionDownloadPath downloadPath = new SameDownloadPathForEveryDistribution(DOWNLOAD_PATH); return downloadConfigBuilder -> { downloadConfigBuilder.downloadPath(downloadPath); downloadConfigBuilder.userAgent(USER_AGENT); }; }
Do you have any ideas on how to proceed?