Spring/코드로 배우는 스프링 웹 프로젝트
프로젝트 생성 및 설정하기
하루인생
2021. 2. 22. 15:50
프로젝트 생성
1) new -> Spring Legacy Project
Spring Legacy Project 로 프로젝트를 생성하면 자동으로 HomeController.java파일과
servlet-context.xml, root-context.xml과 같은 설정파일을 만들어준다.
2) 프로젝트명 입력 -> Spring MVC Project 클릭 -> next -> 패키지명 작성
3) servlet-context.xml과 root-context.xml 파일 자동 생성
servlet-context.xml : 웹과 관련된 스프링 설정 파일
root-context.xml : 스프링 설정 파일
web.xml : 톰캣의 web.xml파일
poom.xml : 메이븐이 사용하는 파일
설정하기
1) pom.xml 수정
스프링 버전을 5.0.7로 수정
<properties>
<java-version>1.6</java-version>
<org.springframework-version>5.0.7.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
수정사항 확인하기
2) 자바 버전 수정
maven-compiler-plugin 부분의 version을 3.5.1, source와 target을 1.8로 수정
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
메이븐 업데이트 후 수정사항 확인
이제 톰캣서버가 설정되어있다면 프로젝트를 실행하게 되면
home.jsp파일이 컨트롤러를 통해 아래와 같이 웹 화면에 보여질 것이다.