How to exclude *AutoConfiguration classes in Spring Boot JUnit tests?

前端 未结 13 1128
名媛妹妹
名媛妹妹 2020-12-01 01:51

I tried:

@RunWith(SpringJUnit4ClassRunner.class)
@EnableAutoConfiguration(exclude=CrshAutoConfiguration.class)
@SpringApplicationConfiguration(classes = Appl         


        
13条回答
  •  粉色の甜心
    2020-12-01 02:28

    I think that the best solution currently for springBoot 2.0 is using profiles

    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
    @ActiveProfiles("test")
    public class ExcludeAutoConfigIntegrationTest {
        // ...
    } 
    

    spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

    anyway in the following link give 6 different alternatives to solve this.

提交回复
热议问题