【问题标题】:DataMongoTest using embeddedMongo fails due to program blocked by group policy (Windows 10)由于程序被组策略阻止(Windows 10),使用 EmbeddedMongo 的 DataMongoTest 失败
【发布时间】:2021-06-02 01:48:19
【问题描述】:

在 Windows 10 中对 Mongo 存储库执行简单的单元测试失败,原因是

java.io.IOException: 无法运行程序 “C:\Users\myuser\AppData\Local\Temp\extract-88ea18ed-75d4-420f-be7f-623baeeb5c70extractmongod.exe”: CreateProcess 错误=1260,此程序被组策略阻止。为了 更多信息,请联系您的系统管理员

这在几天前还有效,但现在可能由于最近的一些 Windows 更新而失败。

失败测试示例

@ExtendWith(SpringExtension.class)
@DataMongoTest
@AutoConfigureDataJpa
@AutoConfigureTestDatabase
@ExtendWith(LogbackSuppressorExtension.class)
@Import(TestConfiguration.class)
class AnnexContentRepositoryTest {
  @Autowired
  private MongoTemplate mongoTemplate;
  @Autowired
  private AnnexContentRepository annexContentRepository;

  @Test
  public void findAllByParentCodeAndParentType() {
    AnnexContent annexContent = addAnnexContent();
    Page<AnnexContent> annexContentResult = annexContentRepository
        .findAllByParentCodeAndParentType(annexContent.getParentCode(), ParentType.THE_ONE,
            Pageable.unpaged());

    Assertions.assertEquals(1, annexContentResult.getTotalElements());
  }

  private AnnexContent addAnnexContent() {
    AnnexContent annexContent = AnnexContentBuilder.buildDefault();

    return mongoTemplate.save(annexContent);
  }
}

【问题讨论】:

    标签: windows mongodb spring-boot spring-data spring-test


    【解决方案1】:

    我找到的解决方案是添加两个嵌入式 mongo 读取的系统变量(“de.flapdoodle.embed.io.tmpdir”和“EMBEDDED_MONGO_ARTIFACTS” ) 在测试配置中(同样适用于使用嵌入式 mongo 运行应用程序,这两个系统变量也可以设置)。

    @Configuration
    public class TestConfiguration {
    
      public TestConfiguration(Environment environment) {
    
        if (SystemUtils.IS_OS_WINDOWS) {
          System.setProperty("de.flapdoodle.embed.io.tmpdir", environment.getProperty("mongo-embedded.windows.temp-dir"));
          System.setProperty("EMBEDDED_MONGO_ARTIFACTS", environment.getProperty("mongo-embedded.windows.temp-dir"));
        }
      }
    }
    

    通过将位置从嵌入的 mongo 默认(“c:\myuser\appdata\local\temp”)更改为,例如,“c:\temp”,问题就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-18
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 2020-01-04
      相关资源
      最近更新 更多