본문 바로가기
IT/Java

spring 예제 part.4

by 성준하이 2021. 12. 17.
반응형

지금까지 프로젝트를 생성하였고

코딩에 앞서서 pom.xml 부분을 점검하고 maven build를 진행해볼것이다.

 

  • 프로젝트명 우클릭 > properties > java build path > library 에서 자바 버전 11 설정
  • pom.xml 설정
<java-version>1.11</java-version>
<org.springframework-version>5.2.5.RELEASE</org.springframework-version>

위 두줄을 찾아서 각자 버전에 맞게 변경해준다.

  • maven build (pom.xml을 변경 후에는 필수)
    프로젝트명 우클릭 > run as > maven clean
    프로젝트명 우클릭 > run as > maven build
    (build가 처음일때는 edit configuration창이 뜨는데 goals 부분에 compile이라고 써주고 실행)

다음으로는 spring이 동작할 서버를 설정해준다.

 

Apache Tomcat® - Apache Tomcat 9 Software Downloads

Welcome to the Apache Tomcat® 9.x software download page. This page provides download links for obtaining the latest version of Tomcat 9.0.x software, as well as links to the archives of older releases. Unsure which version you need? Specification version

tomcat.apache.org

각자의 os에 맞게 파일을 받고 압축을 풀고 각자 편한 경로에 두도록 한다.

나는 어차피 이클립스 안에서만 쓸거 같아서 이클립스 workspace 안에 넣고 폴더 이름도 편하게 tomcat이라고 변경하였다.

 

  • 이클립스에서 tomcat 설정
    이클립스 하단에 servers탭 클릭 후 no servers are available. 문구 클릭.
    apache tomcat9 설정 후 완료 하면 문구가 tomcat9로 변경된다.
    tomcat9 문구를 더블클릭하면 서버 설정 창이 나오는데 여기서 몇개 변경하였다.

    - timeout 부분에서 start 부분을 120초 까지 늘려줬다.
    - 아래 사진에서 modules를 누르고 톰캣이 실행될 웹 루트 디렉토리 지정
      (처음엔 아무것도 없는데 문서 경로는 프로젝트 명과 경로는 최상위 '/'로 지정 하였다. 그리고 control + S 저장)

 

  • 인코딩 설정 (src/main/webapp/WEB-INF/web.xml 파일 수정 
<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

위 코드를 </web-app> 바로 위에 넣도록 한다.

shift + command + F 하면 자동정렬!(이클립스 단축키 포스팅은 아래 참고 포스팅을 확인)

 

  • 모드 설정(필수는 아니지만)
    개발하면서는 수많은 로그를 찍게 된다. 로그를 보면 에러에 대한, 진행에 대한 힌트와 답을 얻을수 있다.
    그렇기에 에러는 중요하고 에러는 많이 나와야 얻을수 있는 정보가 많다.
    에러를 많이 얻기 위해서 로그 레벨을 가장 낮은 debug 모드로 설정을 해야한다.
    src/main/resources/log4j.xml 파일 
<root>
  <priority value="debug" />
  <appender-ref ref="console" />
</root>

</log4j:configuration> 닫히기 전에 이 코드를 추가 했다.

 

여기까지 완료가 된다면 셋팅은 끝이다!


참고 포스팅

이클립스 단축키 관련

https://thenicesj.tistory.com/49

 

eclipse 단축키 모음(mac기준)

내가 많이 쓰는 기준으로! (점점 수정이 될 예정!) command +shift + F = 자동정렬 자동완성 원래는 control + space라는데 난 안먹혀서 설정 > general > key > content assist 에서 command+space로 바꿔줬다...

thenicesj.tistory.com

 

 

반응형

'IT > Java' 카테고리의 다른 글

spring 예제 part.6  (0) 2021.12.20
spring 예제 part.5  (0) 2021.12.19
spring 예제 part.3  (0) 2021.12.16
spring 예제 part.2  (0) 2021.12.14
spring 예제 part.1  (1) 2021.12.13

댓글