[intellij]인텔리제이 스프링 프로젝트 생성

2022. 3. 13. 14:07ALL

반응형

1. new project 에서 maven 선택후 next

 

2. nam은 자기가 원하는 프로젝트명으로 입력후 finish

 - 굳이 groupid, artifactid 등등 넣을필요없다.

3. 프로젝트 우클릭후 spring mvc 선택하고 ok

-위와 같이 트리형태가 생성됨

 

4. lib 폴더를 지워주고 file - project structure - Libraries 에서 두개의 라이브러리 삭제

- 삭제 이유는 pom.xml 에서 따로 관리해줄려고(관리가 용이함)

5. 4번과 같이 제거가 끝났다면 pom.xml 을 아래와 같이 수정

- 수정후 오른쪽 동그라미친 곳을 눌러서 maven 을 로드해준다

[pom.xml]

<properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <org.springframework-version>5.2.3.RELEASE</org.springframework-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>
    </dependencies>

6. 5번을 진행하면 project structure - artifacts 에서 라이브러리들이 생긴것이 보이는데 web-inf로 넣어줌

7.com.controller 패키지 생성후 , HelloController 클래스를 아래와 같이 생성

 

[HelloController]

package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

    @RequestMapping("/")
    public String home() {
        return "index";
    }
}

8. web.xml와 dispatcher-servlet.xml 을 아래와 같이 설정

 

[web.xml]

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

 

[dispatcher-servlet.xml]

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.controller" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

 

9. 톰캣을 사용해 서버를 설정

- 톰캣 설치는 따로 해야됨

vvvvvvv

https://crumber.tistory.com/11?category=458126 

 

[tomcat] 톰캣 설치

1. 톰캣 사이트 https://tomcat.apache.org/ Apache Tomcat® - Welcome! The Apache Tomcat® software is an open source implementation of the Jakarta Servlet, Jakarta Server Pages, Jakarta Expression La..

crumber.tistory.com

 

- /springtest1_war_exploded 부분은 / 로 수정하고 apply 누르고  ok

10.톰캣 실행

- 9번을 진행하면 아래와같이 톰캣이 지정된다.

- 아래 시작 버튼을 누르고

-결과

- index.jsp를 수정하지 않았다면 위 결과가 떠야 정상

 

수고하셨습니다.

반응형

'ALL' 카테고리의 다른 글