[스프링 퀴즈] @Autowired
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class AutowiredTest {
@Autowired DataSource dataSource;
@Test
public void notNull(){
assertThat(dataSource, is(notNullValue()));
}
}
위와 같은 테스트가 있다. 위 코드가 있는 곳과 같은 패키지에 AutowiredTest-context.xml 이라는 빈 설정 파일을 만들었다.
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"/>
</beans>
1. 이렇게 설정했을 때 테스트는 어떻게 될까? 깨질까? 성공할까?
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"/>
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"/>
</beans>
2. 이렇게 설정했다면 어떻게 될까?
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"/>
<bean id="testDataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"/>
</beans>
3. 그럼 이건 어떨까?
셋다 맞춘 분에게 물어보고 싶은 질문이 있는데;; 맞추시는 분께 댓글로 질문 드리겠습니다.