JUnit @BeforeClass non-static work around for Spring Boot application
问题 JUnit's @BeforeClass annotation must be declared static if you want it to run once before all the @Test methods. However, this cannot be used with dependency injection. I want to clean up a database that I @Autowire with Spring Boot, once before I run my JUnit tests. I cannot @Autowire static fields so I need to think of a work around. Any ideas? 回答1: Just use @Before (instead of @BeforeClass ) (or BeforeTransaction (depending on how you initialize the database)). This annotation must been