BackEnd/Spring

Spring 학습 Day2_개발환경 구축

Leo.K 2022. 6. 18. 23:25
  • Java 설치 
    • JDK 1.8설치 
    • cmd창을 열고 java - version을 입력해보면 설치한 자바의 버전 정보를 확인할 수 있다.
  • STS 설치(https://spring.io/tools
    • Eclipse + Spring Plugin
    • IDE툴이란 통합 개발환경으로 코딩, 디버그, 배포 등 프로그램 개발에 관련된 모든 작업을 하나의 프로그램 안에서 처리하는 환경
    • 스프링을 개발하기 위해서는 개발에 필요한 Spring plugin 설치 
    • Eclipse이외의 tool에서도 가능하다.
    • 본인의 OS에 맞는 IDE 버전을 설치
    • 버전이 tools4로 업그레이드 되면서 .jar파일로 바뀌었는데 당황하지 말고 압축을 풀어준다. 그러면 contents.zip파일이 존재하는데 이 파일까지 압축을 풀어주면 실행파일이 나타난다. 
  • Tomcat 설치 
    • Tomcat 8.x
    • 웹 서버와 연동하여 실행할 수 있는 자바 환경을 제공하여 JSP와 Servlet이 실행 할 수 있는 환경을 제공한다.
    • 스프링을 이용한 웹 환경 구성에서 사용 예정

 

[ 프로젝트 생성과 메이븐 설정 ]

  • STS 기본 설정
    • encoding: UTF-8
    • STS에서 사용되는 모든 문자셋을 UTF-8로 맞추고 작업을 해야 추후에 한글이 깨지는 현상을 방지할 수 있음
    • window -> preferences -> General -> content Type -> java class file, java properties file, java source file, jsp, workspace, css, html를 모두 utf-8로 설정 
  • Java설정
    • window -> preference -> java -> installed jres -> jre삭제 & 내가 설치한 jdk경로 설정 -> executions environments -> JavaSE 1.8 -> jdk체크  
  • 스프링 프로젝트 설정

스프링 레거시 프로젝트라고 부른 기존 방식의 스프링 프로젝트. 스프링 부트는 스프링 레거시 프로젝트의 복잡한 xml설정 방식들을 자바 config형태로 즉, annotation형태로 부팅해주는 프로젝트이다. 한국에서는 가장 많이 사용하는 전자 정부 프레임 워크는 스프링 부트를 지원하지 않고 스프링 레거시 프로젝트를 지원한다. 스프링 레거시를 공부하면 스프링 부트는 더 쉽게 사용할 수 있다. 아직까진 실무에서도 스프링 레거시 프로젝트를 더 많이 사용한다고 한다.

  • spring legacy project 생성 
  • simple spring maven
  • 생성된 프로젝트 우클릭 -> configure -> convert to maven -> next
  • 생성된 프로젝트 우클릭 -> properties -> java build path -> library -> jdk 1.8로 설정

 

  • Apache Maven
    • 자바용 프로젝트 관리 도구
    • 빌드, 문서화, 리포팅, 의존관계 관리, 소스코드 관리, 릴리즈, 배포 관리.
    • 균일한 빌드 시스템을 제공
      • pom.xml에 빌드에 관련된 모든 정보를 기술
      • pom.xml에 프로젝트 관련 사항을 기록해놓으면 자동으로 관련 라이브러리 등 설정을 공통으로 사용할 수 있게끔 해주는 플러그 인
    • 라이브러리 의존성 관리

https://mvnrepository.com/

 

Maven Repository: Search/Browse/Explore

extras-core Last Release on Jun 19, 2022

mvnrepository.com

 

위의 주소는 메이븐에서 관리되는 모든 프로젝트와 라이브러리가 올라와 있는 곳이다. 

spring context 5.1.7버전 maven

spring core      5.1.7버전 maven을 복사해서 pom.xml에 붙여넣는다.

더보기
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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>t_tok01</groupId><!-- 내가 속한 그룹ID -->
  <artifactId>t_tok01</artifactId><!-- 나 자신의 고유 ID -->
  <version>0.0.1-SNAPSHOT</version>
  
  <!-- 의존관계 설정하기 -->
  <dependencies>
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.1.7.RELEASE</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.1.7.RELEASE</version>
    </dependency>
    
      
  </dependencies>
</project>
cs

 

혹여나 프로젝트를 진행하는 과정에서 pom.xml을 수정한다면 다음의 과정을 반드시 거쳐야한다.

1. update

2. clean

3. install

 

위의 3가지 작업만을 하고 끝나면 오류가 날것이다. 그 이유는 위에서 설명한 대로 maven이 프로젝트의 "빌드"를 담당해준다고 했는데, 메이븐이 빌드를 할 때 자바 컴파일러 버전이 1.5로 셋팅이 된다. 우리가 초기에 한 환경설정이 무의미해져서 다시 설정해야 한다는 것인데, 그러기엔 너무 불편하니 아래의 사이트에 접속해서 환경설정값을 복사해 pom.xml에 붙여주자. 그러면 메이븐이 초기 빌드시에 1.8버전으로 셋팅을 해줄 것이다. 아래의 사이트에 접속해보자

https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

 

Apache Maven Compiler Plugin – Setting the -source and -target of the Java Compiler

Setting the -source and -target of the Java Compiler Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can als

maven.apache.org

 

[ pom.xml ]

더보기
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
32
33
34
35
36
37
38
39
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>t_tok01</groupId><!-- 내가 속한 그룹ID -->
  <artifactId>t_tok01</artifactId><!-- 나 자신의 고유 ID -->
  <version>0.0.1-SNAPSHOT</version>
  
  <!-- 의존관계 설정하기 -->
  <dependencies>
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.1.7.RELEASE</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.1.7.RELEASE</version>
    </dependency>
  </dependencies>
  
  
  <!-- 프로젝트가 빌드될 때 컴파일러 버전 설정 -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
cs

'BackEnd > Spring' 카테고리의 다른 글

SpringCollection_국비Day82  (0) 2022.06.28
Spring학습_Day4_AOP  (0) 2022.06.28
Spring_국비Day81  (0) 2022.06.27
Spring 학습_Day3_IoC_DI  (0) 2022.06.20
Spring 학습 Day1_개요 및 특징  (0) 2022.06.18