Чего я пытаюсь достичь: < /p>
Запустите интеграционный тест для контроллера пружины в тестовом контейнере, используйте TestJpaconfig вместо jpaconfig: < /p>
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
@Testcontainers
@ComponentScan(excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = JpaConfig.class)
})
@Import(TestJpaConfig.class)
public class SomeControllerIT {
@Container
static PostgreSQLContainer postgresContainer = new PostgreSQLContainer...
@DynamicPropertySource
static void overrideProperties(DynamicPropertyRegistry registry) {
...
}
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@MockBean
Bean beans...
@Autowired
Class classes...
@BeforeEach
void setup() {
...
}
@Test
void test_Something() throws Exception {
...
}
}
< /code>
У меня есть эта ошибка: < /p>
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'jpaAuditingHandler' defined in null: Cannot register bean definition [Root bean: class [org.springframework.data.auditing.AuditingHandler]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=from; initMethodNames=null; destroyMethodNames=null] for bean 'jpaAuditingHandler' since there is already [Root bean: class [org.springframework.data.auditing.AuditingHandler]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=from; initMethodNames=null; destroyMethodNames=null] bound.
< /code>
my jpaconfig: < /p>
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class JpaConfig {
@Bean
public AuditorAware auditorProvider() {
return new SpringSecurityAuditorAware();
}
}
< /code>
и My testjpaconfig: < /p>
@TestConfiguration
@EnableJpaAuditing(auditorAwareRef = "testAuditorProvider")
public class TestJpaConfig {
@Bean(name = "test")
public AuditorAware auditorProvider() {
return () -> Optional.of(1L);
}
}
< /code>
Я попытался работать, чтобы исправить эту ошибку без успеха, обращая здесь помощь сейчас, какие -нибудь идеи? У меня есть ограниченные знания весной.
Подробнее здесь: https://stackoverflow.com/questions/795 ... on-testing
Ошибка при попытке использовать тестовую конфигурацию JPA в тестировании интеграции ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Ошибка при попытке использовать тестовую конфигурацию JPA в тестировании интеграции
Anonymous » » в форуме JAVA - 0 Ответы
- 9 Просмотры
-
Последнее сообщение Anonymous
-