title: Configuration error: found multiple declarations of @BootstrapWith for test class for @WebMvcTest and @DataJpaTest
body: <p>I have an entitie <code>PetBE</code> and I want to write an end to end test where a request updates the database.</p>
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  @Entity
  @Table(name = &quot;pets&quot;)
  public class PetBE {
      
      @Id
      private long id;
  
      @NonNull
      private String name;
  
  }
  </code></pre>
  <p>It works fine if I just test the database</p>
  <pre><code>@DataJpaTest
  public class SetupTests {
  
      @Test
      @Sql(&quot;onePet.sql&quot;)
      void dummytest() {
          assertThat(1).isEqualTo(1);
      }
  }
  </code></pre>
  <p>or just a request but the database is mocked. However when I try both, I get an error:</p>
  <pre><code>@ExtendWith(SpringExtension.class)
  @WebMvcTest(controllers = PetController.class)
  @DataJpaTest
  public class E2ETest {
  
      @Autowired
      private ObjectMapper objectMapper;
  
      @MockBean
      private PetRepository pr;
  
      @Test
      @Sql(&quot;onePet.sql&quot;)
      void whenPetExists_thenReturns200() throws Exception {
          //mockMvc.perform(put(&quot;/pet&quot;)...
          assertThat(1).isEqualTo(1);
      }
  }
  </code></pre>
  <p>namely</p>
  <pre><code>Configuration error: found multiple declarations of @BootstrapWith for test class [com.example.petstore.backend.api.implementation.E2ETest]: [@org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper)]
  java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.example.petstore.backend.api.implementation.E2ETest]: [@org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper)]
      at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:166)
      at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:127)
  </code></pre>
  <p>It seems like <code>@WebMvcTest</code> and <code>@DataJpaTest</code> are mutually exclusive, but I clearly need <code>@WebMvcTest</code> and without <code>@DataJpaTest</code> I get</p>
  <pre><code>Failed to execute SQL scripts for test context [DefaultTestContext@703ec858 testClass = E2ETest, testInstance = com.example.petstore.backend.api.implementation.E2ETest@1005e0c5, testMethod = whenPetExists_thenReturns200@E2ETest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@678e04d0 testClass = E2ETest, locations = '{}', classes = '{class com.example.petstore.PetstoreApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@74ce371b, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@3ca253f3, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@117223fd, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4b5bf35f, [ImportsContextCustomizer@5ff8aba2 key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration, org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration, org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration, org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration, org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration, org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration, org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration, org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration, org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration, org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration, org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration, org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration, org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5cbc6bb6, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2641cd8, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@e1051f26, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]: supply at least a DataSource or PlatformTransactionManager.
  java.lang.IllegalStateException: Failed to execute SQL scripts for test context [DefaultTestContext@703ec858 testClass = E2ETest, testInstance = com.example.petstore.backend.api.implementation.E2ETest@1005e0c5, testMethod = whenPetExists_thenReturns200@E2ETest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@678e04d0 testClass = E2ETest, locations = '{}', classes = '{class com.example.petstore.PetstoreApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@74ce371b, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@3ca253f3, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@117223fd, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4b5bf35f, [ImportsContextCustomizer@5ff8aba2 key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration, org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration, org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration, org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration, org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration, org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration, org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration, org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration, org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration, org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration, org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration, org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration, org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration, org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration, org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5cbc6bb6, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2641cd8, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@e1051f26, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]: 
  supply at least a DataSource or PlatformTransactionManager.
      at org.springframework.util.Assert.state(Assert.java:97)
      ...
  </code></pre>
  <p>So I think I need this one as well. How can I get those two annotatins to work together?</p>