Java 如何在spring中运行post配置代码
在我的测试中,我需要一些静态配置(rest客户端)。此代码应该在加载所有配置文件之后但在任何测试之前运行。它不产豆子Java 如何在spring中运行post配置代码,java,spring,spring-boot,Java,Spring,Spring Boot,在我的测试中,我需要一些静态配置(rest客户端)。此代码应该在加载所有配置文件之后但在任何测试之前运行。它不产豆子 @TestConfiguration class Config { // how to annotate this method? @PostConstruct won't work. it's not a @Bean as it's void fun postConfiguration(env: Environment) {
@TestConfiguration
class Config {
// how to annotate this method? @PostConstruct won't work. it's not a @Bean as it's void
fun postConfiguration(env: Environment) {
SomeClass.staticField = env.getProperty("xyz")
}
}
如何执行此方法?
@Autowired
注释将完成以下操作:
@TestConfiguration
class Config {
@Autowired
fun postConfiguration(env: Environment) {
SomeClass.staticField = env.getProperty("xyz")
}
}
@Autowired
以上你的方法会成功的。@Tashkhhisi,真的,谢谢你!如果您添加答案,我将接受您无法更改的第三方库中的ISSomeClass
。@chrylis小心光学是的,我需要为测试设置外部库。但这会改变什么吗?如果是我的代码,有哪些选项?