Я хочу иметь тест JPA с использованием специального тестового профиля весны. Но почему-то это не позволяет загрузить весенний контекст.@DataJpaTest перестает работать с аннотацией @Profile
@RunWith(SpringRunner.class)
@Profile("myTestProfile")
@DataJpaTest
@ContextConfiguration(classes = {TestingConfig.class, MyJpaConfig.class})
public class JpaPlusOtherStuffTest {
@Autowired
private TestEntityManager testEntityManager;
...
@Autowired
private MyJpaRepository myJpaRepository;
}
завершается с ошибкой при слежении:
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'myJpaRepository':
Cannot create inner bean '(inner bean)#5e77f0f4' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5e77f0f4':
Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'entityManagerFactory' is defined
Если удалить @Profile
аннотацию, то тест работает нормально. Я просто не понимаю, как выполнить дополнительный профиль @DataJpaTest
. Может быть, кто-нибудь может объяснить это мне?
UPD Вот мой MyJpaConfig
:
@Configuration
@EnableJpaAuditing
@EnableJpaRepositories("com.mycompany.project.jpa")
@EnableTransactionManagement(proxyTargetClass = true)
public class MyJpaConfig {
}
можете ли вы разместить конфигурацию пружины? –
@AngeloImmediata добавлен. Другая конфигурация не имеет значения. Может быть пустым –