본문 바로가기
풀스택/Spring -Junit

스프링 xml과 javaconfig 같이 쓰기 - guestbook4

by woohyun22 2019. 3. 20.

1. maven project 생성


2. maven check 후, com.douzone, guestbook4, jar로 생성


3. 3의 pom.xml에서 4로 properties부터 /build까지 복붙


3-1 properties 안에 


1
2
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
cs

추가


4. 3의 webapp에서 4로 복붙, web.xml만 남기고 xml지우기


5. project property -build path, deployment Assembly 에서 webapp 정리 , target Runtime에서 톰캣설정 후 , 프로젝트 우클릭 메이븐 업데이트


6. 3의 controller,dao,vo 옮기기 및 com.douzone.guestbook.config  패키지 생성


7. 패키지 안에 RootConfig , WebConfig 생성


RootConfig - ComponentScan 설정은 다르게


1
2
3
4
@Configuration
@ComponentScan("com.douzone.guestbook.dao")
public class RootConfig {
}
cs


WebConfig - ComponentScan 설정은 다르게


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Configuration
@EnableWebMvc
@ComponentScan("com.douzone.guestbook.controller")//자동 설정 사용
public class WebConfig {
    //여기서 하는건 명시적 설정
    @Bean
    public ViewResolver viewResolover() {
        InternalResourceViewResolver resolver = 
                new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        resolver.setExposeContextBeansAsAttributes(true);
        return resolver;
        
    }
}
cs


8. web.xml 수정 및 추가 -guestbook 부분 바꿔주기


---  context-param 수정

1
2
3
4
5
6
7
8
<context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.douzone.guestbook.config.RootConfig</param-value>
    </context-param>
cs


---  servlet 수정

1
2
3
4
5
6
7
8
9
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>com.douzone.guestbook.config.WebConfig</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
cs



9. GuestbookController의 /WEB-INF/views/ 및  .jsp 빼주기


10. jsp .jsp 빼주기


11. local 돌려보기 오류가 난다면 - emaillist, gestbook 등 이름이 잘못된 경우가 많음 알아서 바꾸기

728x90

댓글