Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 访问Junit ClassRule中的spring boot application.properties元素_Spring Boot_Spring Boot Test - Fatal编程技术网

Spring boot 访问Junit ClassRule中的spring boot application.properties元素

Spring boot 访问Junit ClassRule中的spring boot application.properties元素,spring-boot,spring-boot-test,Spring Boot,Spring Boot Test,我想在junit静态类规则中访问资源/属性文件元素(在下面的代码中是its的cardEventTopic和cardEventErrorTopic常量)。有没有办法做到这一点?由于这些元素已经存在于属性文件中,我不想将它们作为静态常量放在测试文件中。另外,@Value(“${}”)不能与静态上下文一起使用。如果有办法,请提供任何帮助 @RunWith(SpringRunner.class) @SpringBootTest(类=PaymentAccountUpdaterApplication.cla

我想在junit静态类规则中访问资源/属性文件元素(在下面的代码中是its的
cardEventTopic
cardEventErrorTopic
常量)。有没有办法做到这一点?由于这些元素已经存在于属性文件中,我不想将它们作为静态常量放在测试文件中。另外,
@Value(“${}”)
不能与静态上下文一起使用。如果有办法,请提供任何帮助

@RunWith(SpringRunner.class)
@SpringBootTest(类=PaymentAccountUpdaterApplication.class,
webEnvironment=SpringBootTest.webEnvironment.NONE)
@TestPropertySource(locations=“classpath:application messaging.properties”)
公共类心脏综合测试{
私有最终静态字符串cardEventTopic=“TP.PRF.CARDEVENTS”;
私有最终静态字符串cardEventErrorTopic=“TP.PAYMENTS.CARDEVENTS.ERRORS”;
@阶级规则
公共静态卡夫卡密德卡夫卡密德=
新卡夫卡嵌入(1,false,cardEventTopic,cardEventErrorTopic);
//代码的其余部分
}

您可以通过类注释定义embeddedKafka,并在其中使用spEL定义主题:

@EmbeddedKafka(主题={${my.topic1},“${my.topic2}”)
或者,您可以在任何配置类中将EmbeddedKafka定义为一个单独的bean,并提供所需的所有属性

别忘了自动连线

@Autowired
私人嵌入卡夫卡卡布罗克嵌入卡夫卡;