@DataJpaTest и @WebMvcTest перестали работать после обновления до 2.2.0 - PullRequest
0 голосов
/ 25 октября 2019

После обновления 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.

1 Ответ

0 голосов
/ 30 октября 2019

Основной причиной проблемы была аннотация @ComponentScan для класса приложения, заменив @ComponentScan на @SpringBootApplication (scanBasePackages = "com.example"), чтобы решить эту проблему.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...