티스토리 뷰

엥 됐다가 안됐다가 합니다..휴....... 이유 파악중....

결론!!! 저는 안되는데 누군가는 될 수 있으니 참고하시라 1번은 됐다구요.... 

저는 나중에 다시 알아볼 예정임

 

 

코드로배우는 스프링 웹 프로젝트 작성 중 jUnit으로 테스트할 때 java설정을 이용하려고 하기만 하면(p.64)

 

failed to load ApplicationContext

 

 

cannot load configuration class org.zerock.config.rootconfig

 

라고 떠서 이유를 찾으려 해도 왠걸, 공식 카페에도 내용이 없네

 

해결 방법은 아래와 같다.

 

테스트할 클래스 파일에 어노테이션 @WebAppConfiguration 을 더한다

import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.zerock.config.RootConfig;

import lombok.Setter;
import lombok.extern.log4j.Log4j;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = { RootConfig.class })
@Log4j
public class SampleTests {

	@Setter(onMethod_ = { @Autowired })
	private Restaurant restaurant;

	@Test
	public void testExist() {
		assertNotNull(restaurant);

		log.info(restaurant);
		log.info("------------------");
		log.info(restaurant.getChef());
	}

}

 

 

이러면 이제 javax.servlet.SessionCookieConfig가 없다느니 하는 말이 나오면서 또 에러가 생긴다.

(아니라면 잘되는 것이고.. 그것도 아니면 다른 문제겠지)

 

pom.xml에 javax.servlet 디펜던시를 수정한다. << 나는 artifactId, version 수정 >>

 

		<!-- Servlet -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>

 

 

테스트가 완료되었다!

 

728x90
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함