embedded redis를 사용하면서 스프링 컨텍스트가 종료되지 않아 embedded redis가 포트 충돌이 생기는 문제가 발생했습니다.
이 부분을 해결하면서 아래와 같은 궁금점이 생겼습니다.
위와 같은 궁금점으로 스프링공식문서에서 Spring TestContext Framework가 제공하는 Context Management, Context Caching을 정리하게 되었습니다.
틀린 내용이 있다면 댓글로 의견 주시면 감사하겠습니다🙇
test suite: 같은 JVM에서 실행되는 모든 테스트들
Component Classes
The term “component class” can refer to any of the following:
A class annotated with @Configuration.
A component (that is, a class annotated with @Component, @Service, @Repository, or other stereotype annotations).
A JSR-330 compliant class that is annotated with javax.inject annotations.
Any class that contains @Bean-methods.
Any other class that is intended to be registered as a Spring component (i.e., a Spring bean in the ApplicationContext), potentially taking advantage of automatic autowiring of a single constructor without the use of Spring annotations.
See the javadoc of @Configuration and @Bean for further information regarding the configuration and semantics of component classes, paying special attention to the discussion of @Bean Lite Mode.
@ExtendWith(SpringExtension.class)
// specifies the Spring configuration to load for this test fixture
@ContextConfiguration("repository-config.xml")
class HibernateTitleRepositoryTests {
// this instance will be dependency injected by type
@Autowired
HibernateTitleRepository titleRepository;
@Test
void findById() {
Title title = titleRepository.findById(new Long(10));
assertNotNull(title);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- this bean will be injected into the HibernateTitleRepositoryTests class -->
<bean id="titleRepository" class="com.foo.repository.hibernate.HibernateTitleRepository">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- configuration elided for brevity -->
</bean>
</beans>
locations
(from @ContextConfiguration
)classes
(from @ContextConfiguration
)contextInitializerClasses
(from @ContextConfiguration
)contextCustomizers
(from ContextCustomizerFactory
) – this includes @DynamicPropertySource
methods as well as various features from Spring Boot’s testing support such as @MockBean
and @SpyBean
.contextLoader
(from @ContextConfiguration
)parent
(from @ContextHierarchy
)activeProfiles
(from @ActiveProfiles
)propertySourceLocations
(from @TestPropertySource
)propertySourceProperties
(from @TestPropertySource
)resourceBasePath
(from @WebAppConfiguration
)