由于@SpringApplicationConfiguration@WebIntegration在Spring Boot Framework中已被弃用,因此正确的注释是什么?
2022-08-31 14:11:45
自Spring Boot Framework 1.4以来并已弃用的正确注释是什么?我正在尝试单元测试。@SpringApplicationConfiguration
@WebIntegration
自Spring Boot Framework 1.4以来并已弃用的正确注释是什么?我正在尝试单元测试。@SpringApplicationConfiguration
@WebIntegration
看看不推荐使用的类的JavaDocs:
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.context.SpringBootTest} with
* {@code webEnvironment=RANDOM_PORT} or {@code webEnvironment=DEFINED_PORT}.
*/
...
@Deprecated
public @interface WebIntegrationTest {
* @deprecated as of 1.4 in favor of {@link SpringBootTest} or direct use of
* {@link SpringBootContextLoader}.
*/
...
@Deprecated
public @interface SpringApplicationConfiguration {
还有 TestRestTemplate() 的替代品吗?
是的,这里是:
* @deprecated as of 1.4 in favor of
* {@link org.springframework.boot.test.web.client.TestRestTemplate}
*/
@Deprecated
public class TestRestTemplate extends RestTemplate {
现在可能是一个好的起点:测试Spring Boot 1.4中的改进。
它们描述了一个基本示例,如下所示:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class MyTest {
}
作为替代,许多以下之一:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(MyApp.class)
@WebIntegrationTest
public class MyTest {
}