0

こんにちは、私は春のブート プロジェクトを行っており、統合テストを行っています。私の統合テストでは、組み込みのエラスティック検索インスタンスを開始する必要があります。次のように弾性検索構成を定義する application.yml ファイル (src/test/resources/config/application.yml) があります。

elasticsearch:
    configuration:
        clustername: my-cluster
        host: localhost
        port: 57457

だから私は私のjunitテストでこの値を取得する必要があります。ただし、 @Value アノテーションは静的フィールドでは機能しないことがわかりました。yml ファイルから値を正しく取得する方法を教えてください。

@RunWith(SpringRunner.class)
@SpringBootTest(classes = PrimecastApp.class)
public class PerformanceReportingIntTest extends AbstractCassandraTest {

    @Autowired
    private PerformanceReportingService performanceReportingService;

    @Autowired
    private HttpMessageConverter[] httpMessageConverters;

    @Autowired
    private ExceptionTranslator exceptionTranslator;

    @Value("${elasticsearch.configuration.host}")
    private final static String host = null;

    @Value("${elasticsearch.configuration.port}")
    private final static int port = 0;

    private static EmbeddedElastic embeddedElastic;

    private static RestHighLevelClient client;

    @BeforeClass
    public static void startElasticServer() throws FileNotFoundException, IOException, InterruptedException {


        embeddedElastic = EmbeddedElastic.builder().withElasticVersion("6.6.1")
                .withSetting(PopularProperties.HTTP_PORT, port)
                .withSetting(PopularProperties.CLUSTER_NAME, "my_cluster").withStartTimeout(5, TimeUnit.MINUTES)
                .withIndex("cars", IndexSettings.builder().withType("car", getSystemResourceAsStream()).build()).build()
                .start();

        client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, "http")));


    }

助けてくれてありがとう

4

0 に答える 0