본문 바로가기
kosta/Spring

Maven 기반 Spring 프로젝트 생성!

by 엑츄얼리 2022. 5. 18.

Add FrameWork 없이 pom.xml와 프로젝트 설정만 가지고 구축해보고 싶었다.

 

1. New Project 아래와 같이 Maven (Java ver.11)로 프로젝트 생성

 

2. 

Project Structure을 확인해보면 아무것도 없다. (module, facet, artifacts 모두 비어있다.)

 

3. pom.xml 에 spring-webmvc를 추가

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>book.web.spring</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>

        <java-version>11</java-version>
        <org.springframework-version>5.0.7.RELEASE</org.springframework-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
    </dependencies>
</project>

 

4. Project Structure -> Module을 보면 Spring이 추가되어있다.

   1) [Add]를 통해 Web을 추가해추고 Web을 클릭,

   2) [Add Application Server specific descriptor...]을 통해 Tomcat을 추가

       (Create Application Server Specific Descriptor 확인)

3) 우측 하단에 [Creaet Artifact]을 통해 해당 Web Service의 Artifact 추가!

 

5. Artifact에서 pom.xml을 통해 설치한 mvc-web library를 artifact에 추가

 

6. tomcat 설정 및 Artifact 추가

 

여기까지 설정하면 웹페이지가 작동한다.

추가적으로 필요한 library들은 pom.xml에 추가하여 진행하면 된다!

 

7. 추가적으로 WEB-INF에 root-context와 servlet-context를 생성해준다.

   root-context와 sevlet-context : Spring 설정 파일

 1) servlet-context.xml

    request와 관련된 bean을 정의 (DispatcherServlet과 관련된 설정)

    controller, @(bean), ViewResolver, Interceptor, MultipartResolver

 

 2) root-context.xml

    servlet-context.xml과 반대로 view와 관련되지 않은 bean을 정의

    Service, Repository(DAO), DB등 비즈니스 로직과 관련된 설정

 

 3) web.xml

    최초로 WAS가 구동될 때, 각종 설정을 정의 (여러 xml파일을 인식하도록 각 파일을 가리켜 줌)

 

https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc

ref. https://jwj1699.tistory.com/13

 

IntelliJ에서 스프링MVC 프로젝트 만들기

이제 막 IntelliJ를 사용하기 시작했는데 이클립스와 너무달라서 스프링 프로젝트조차 만들기가 힘들다ㅠㅠ sts에서 Spring MVC 프로젝트를 생성하면 기본구조가 설정되었는데 IntelliJ는 프로젝트 생

jwj1699.tistory.com

 

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

@ModelAttribute 추가 이해  (0) 2022.06.14
Spring 기초3(실습)  (0) 2022.05.18
Spring 기초2(실습)  (0) 2022.05.16
Spring 기초(실습)  (0) 2022.05.12

댓글