Java flapdoodle.embed.mongo总是从Eclipse中的Spring Boot主应用程序开始,如何删除

Java flapdoodle.embed.mongo总是从Eclipse中的Spring Boot主应用程序开始,如何删除,java,spring,mongodb,spring-boot,Java,Spring,Mongodb,Spring Boot,我有个问题。一个简单的spring引导应用程序可以很好地与现有的MongoDB配置配合使用。 对于集成测试,我添加了嵌入式mongodb所需的配置,带有活板门配置。所有的单元测试都得到了正确的执行。当我运行主Spring引导应用程序时,默认情况下,它会考虑Flappodle嵌入的mongodb配置。因此,嵌入式mongodb永远不会退出,在运行junit测试用例时,它仍然会运行。我在下面提供代码片段 每当我启动SpringBoot主应用程序时,它仍然运行嵌入式mongodb。我总是在控制台中看到

我有个问题。一个简单的spring引导应用程序可以很好地与现有的MongoDB配置配合使用。 对于集成测试,我添加了嵌入式mongodb所需的配置,带有活板门配置。所有的单元测试都得到了正确的执行。当我运行主Spring引导应用程序时,默认情况下,它会考虑Flappodle嵌入的mongodb配置。因此,嵌入式mongodb永远不会退出,在运行junit测试用例时,它仍然会运行。我在下面提供代码片段

每当我启动SpringBoot主应用程序时,它仍然运行嵌入式mongodb。我总是在控制台中看到以下行

Download PRODUCTION:Windows:B64 START
Download PRODUCTION:Windows:B64 DownloadSize: 231162327
Download PRODUCTION:Windows:B64 0% 1% 2% 3% 4% 5% 6% 7% 8% 
我提供了Mongodb配置的代码,在运行主Spring引导应用程序时应该选择该代码

@Slf4j
@Configuration
public class NoSQLAutoConfiguration {

    @Autowired
    private NoSQLEnvConfigProperties configProperties;

    /**
     * Morphia.
     *
     * @return the morphia
     */
    private Morphia morphia() {
        final Morphia morphia = new Morphia();
        morphia.mapPackage(DS_ENTITY_PKG_NAME);
        return morphia;
    }


    @Bean
    public Datastore datastore(@Autowired @Qualifier("dev") MongoClient mongoClient) {
        String dbName = configProperties.getDatabase();
        final Datastore datastore = morphia().createDatastore(mongoClient, dbName);
        datastore.ensureIndexes();

        return datastore;
    }

    /**
     * Mongo client.
     *
     * @return the mongo client
     */
    @Primary
    @Bean(name = "dev")
    public MongoClient mongoClient() {
        MongoClient mongoClient = null;
        String dbHost = configProperties.getHost();
        int dbPort = configProperties.getPort();
        String database = configProperties.getDatabase();
        log.debug("MongDB Host: {} - MongoDB Port: {}", dbHost, dbPort);
        List<ServerAddress> serverAddresses = new ArrayList<>();
        serverAddresses.add(new ServerAddress(dbHost, dbPort));
        MongoClientOptions options = getMongoOptions();
        String dbUserName = configProperties.getMongodbUsername();
        String encRawPwd = configProperties.getMongodbPassword();
        char[] dbPwd = null;
        try {
            dbPwd = Util.decode(encRawPwd).toCharArray();
        } catch (Exception ex) {
            // Ignore exception
            dbPwd = null;
        }
        Optional<String> userName = Optional.ofNullable(dbUserName);
        Optional<char[]> password = Optional.ofNullable(dbPwd);

        if (userName.isPresent() && password.isPresent()) {
            MongoCredential credential = MongoCredential.createCredential(dbUserName, database, dbPwd);
            List<MongoCredential> credentialList = new ArrayList<>();
            credentialList.add(credential);
            mongoClient = new MongoClient(serverAddresses, credentialList, options);
        } else {
            log.debug("Connecting to local Mongo DB");
            mongoClient = new MongoClient(dbHost, dbPort);
        }
        return mongoClient;
    }

    
    private MongoClientOptions getMongoOptions() {
        MongoClientOptions.Builder builder = MongoClientOptions.builder();
        builder.maxConnectionIdleTime(configProperties.getMongodbIdleConnection());
        builder.minConnectionsPerHost(configProperties.getMongodbMinConnection());
        builder.connectTimeout(configProperties.getMongodbConnectionTimeout());
        return builder.build();
    }

}
请帮助我如何在eclipse中运行Spring Boot主应用程序时删除此嵌入式mongo配置

我也在下面提供我的主要应用程序

@EnableAspectJAutoProxy
@EnableSwagger2
@SpringBootApplication(scanBasePackages = { "com.blr.app" })
public class ValidationApplication {

    /**
     * The main method. f
     * 
     * @param args the arguments
     */
    public static void main(String[] args) {
        SpringApplication.run(ValidationApplication.class, args);
    }

}

我看到您没有向
MongoConfiguration
类添加任何配置文件的代码。在eclipse构建期间,Spring框架也会获取此类。将下面的行添加到此类中,以便在运行Spring Boot test时拾取该类,并在运行主Spring Boot app时拾取实际的Mongo配置文件。这就是Spring提出概念概要的原因。为不同的环境适当地添加配置文件

@Profile("test")
@ActiveProfiles("test")
最后的代码是这样的

@Profile("test")
@ActiveProfiles("test")
@TestConfiguration
public class MongoConfiguration implements InitializingBean, DisposableBean {
   ...
   ...
}

让我检查两个都运行。它工作正常。谢谢。
@Profile("test")
@ActiveProfiles("test")
@TestConfiguration
public class MongoConfiguration implements InitializingBean, DisposableBean {
   ...
   ...
}