После обновления Spring Boot с 2.1.8 до 2.2.0 тесты, которые не загружают полный контекст приложения, начали давать сбой.
@DataJpaTest
@TestPropertySource(properties = "spring.jpa.hibernate.ddl-auto=none")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class MyRepositoryTest {
@Autowired private TestEntityManager entityManager;
@Autowired private MyRepository repository;
@Test
public void test() {
....
}
Это приводит к следующей ошибке
20:44:35.866 [main] [ERROR] o.s.b.d.LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method rabbitTemplate in com.example.boot.message.amqp.AmqpConfig required a bean of type 'org.springframework.amqp.rabbit.connection.ConnectionFactory' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.amqp.rabbit.connection.ConnectionFactory' in your configuration.
IЯ получаю ту же ошибку на @WebMvcTest, но раньше оба прекрасно работали.
Инъекция завершается неудачно в классе @RestController, который, я думаю, не должен сканироваться и загружаться для @DataJpaTest.