Spring Legacy (IntelliJ)

Eclipse์—์„œ spring framework๋ฅผ ์ด์šฉํ•œ ์›น ๊ฐœ๋ฐœ์„ ํ•  ๋•Œ๋Š”

STS(Spring Tool Suite)์˜ ๋„์›€์„ ๋ฐ›๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ 

์›๋ž˜ Spring framework๋Š” STS์˜ ๋„์›€ ์—†์ด๋„ maven์„ ํ†ตํ•ด ํ™˜๊ฒฝ ๊ตฌ์ถ•์ด ์ถฉ๋ถ„ํžˆ ๊ฐ€๋Šฅํ•˜๋‹ค.

ํ•˜์ง€๋งŒ IntelliJ์—์„œ๋Š” ๊ทธ๋Ÿฐ ๊ธฐ๋Šฅ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค.

๋‹ค๋งŒ ์ƒ๋Œ€์ ์œผ๋กœ eclipse ์‚ฌ์šฉ์ž๊ฐ€ ๋” ๋งŽ์•„ eclipse์˜ STS๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ํฌ์ŠคํŒ…์ด ๋Œ€๋ถ€๋ถ„

์šฐ๋ฆฌ๋Š” STS ๋“ฑ์˜ extension์ด๋‚˜ Plugin์— ์˜์กดํ•˜์ง€ ์•Š๊ณ  ์ˆœ์ˆ˜ maven ์„ ํ™œ์šฉํ•ด

Spring framework๋ฅผ ์‚ฌ์šฉํ•ด๋ณผ ๊ฒƒ

์ถ”ํ›„์—๋Š” https://start.spring.io/ ๋ฅผ ํ†ตํ•ด ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ

Spring framework๋Š” ์ฒ˜์Œ์— ์ง„์ž…์žฅ๋ฒฝ์ด ์žˆ๋Š” ํŽธ

๋งŽ์€ ์„ค์ •๋“ค๊ณผ, ๊ทธ ์›๋ฆฌ๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฐ๊ฒฝ์ง€์‹์ด ํ•„์š”ํ•จ.

ํŠนํžˆ ์—ฌ๋Ÿฌ ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ STS๋กœ ์„ค์ •์„ ํ•ด์„œ ์‹œ์ž‘ํ•˜๋ฉด

์Šคํ”„๋ง์˜ ๊ธฐ๋ณธ์›๋ฆฌ์— ๋Œ€ํ•ด์„œ ์ดํ•ดํ•˜์ง€ ๋ชปํ•œ ์ฑ„ ๋‹จ์ˆœํžˆ ์‚ฌ์šฉํ•  ์ˆ˜ ๋งŒ ์žˆ๋Š” ์ƒํƒœ๊ฐ€ ๋จ

STS ๋“ฑ์˜ extension์ด๋‚˜ plugin์— ์˜์กด์ ์ด์ง€ ์•Š๊ณ  ์ˆœ์ˆ˜ํ•˜๊ฒŒ maven์„ ํ™œ์šฉํ•˜์—ฌ

spring framework ๋ฅผ ์‹œ์ž‘ํ•ด๋ณผ ๊ฒƒ์ž„

*Spring Legacy

  • ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์ด๋ž€?

๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์€ ์˜ค๋žœ ๊ธฐ๊ฐ„ ๋™์•ˆ ์šด์˜๋˜์–ด์˜จ ์‹œ์Šคํ…œ์œผ๋กœ, ๊ณผ๊ฑฐ์— ๊ฐœ๋ฐœ๋œ ๊ธฐ์ˆ ๊ณผ ๋ฐฉ๋ฒ•๋ก ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์‹œ์Šคํ…œ์€ ์ฃผ๋กœ ์—…๋ฌด ๋กœ์ง์ด ๋ณต์žกํ•˜๊ณ  ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ต๋‹ค๋Š” ํŠน์ง•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์€ ์ƒˆ๋กœ์šด ์š”๊ตฌ์‚ฌํ•ญ์— ๋Œ€ํ•œ ๋Œ€์‘์ด ์–ด๋ ต๊ณ , ํ™•์žฅ์„ฑ์ด ์ œํ•œ์ ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ์™€ ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ

์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์˜ ๊ฐœ๋ฐœ๊ณผ ์œ ์ง€๋ณด์ˆ˜๋ฅผ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์Šคํ”„๋ง์€ DI ์™€ AOP ๋“ฑ์˜ ๊ฐœ๋…์„ ๋„์ž…ํ•ด ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์˜ ์ฝ”๋“œ๋ฅผ ๋ถ„๋ฆฌํ•˜๊ณ  ์œ ์—ฐ์„ฑ์„ ๋†’์—ฌ ์ค๋‹ˆ๋‹ค.

  • ์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ๋“ฑ์žฅ๊ณผ ์ฐจ์ด์ 

์Šคํ”„๋ง ๋ถ€ํŠธ๋Š” ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ• ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์Šคํ”„๋ง ๋ถ€ํŠธ๋Š” ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์˜ ์„ค์ •๊ณผ ๋ฐฐํฌ๋ฅผ ๊ฐ„ํŽธํ•˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค. ์Šคํ”„๋ง ๋ถ€ํŠธ๋Š” ์ž๋™ ์„ค์ •๊ณผ ๋‚ด์žฅ ์„œ๋ฒ„ ๋“ฑ์˜ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ด ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ณ„๋„์˜ ์„ค์ • ์—†์ด๋„ ๊ฐ„๋‹จํžˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰, ๋ฐฐํฌ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ƒ์‚ฐ์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ค๊ณ  ๊ฐœ๋ฐœ ์‹œ๊ฐ„์„ ๋‹จ์ถ• ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

์ƒˆํƒํ”„๋กœ์ ํŠธ์„ ํƒ ํ›„ ํ”„๋กœ์ ํŠธ์˜ ์ด๋ฆ„๊ณผ location ์„ค์ •

๊ณ ๊ธ‰ ์„ค์ • ํด๋ฆญ ํ›„

๊ทธ๋ฃน ID ๋ณ€๊ฒฝ ํ›„ ์•„ํ‹ฐํŒฉํŠธ ID ํ™•์ธ ํ›„ ์ƒ์„ฑ!

์ง€์ •ํ•œ ๊ทธ๋ฃน ID์— ๋”ฐ๋ผ์„œ java ์•„๋ž˜์— ํŒจํ‚ค์ง€๊ฐ€ ์ƒ์„ฑ๋จ

pom.xml ์ด ์ž˜ ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ!

2. pom.xml ์„ค์ •

pom.xml์— ๋‚ด์šฉ ์ถ”๊ฐ€ ํ›„ maven reload

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <org.springframework-version>6.1.0</org.springframework-version>
</properties>

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

3. ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์„ค์ •

๋ชจ๋“ˆ ์„ ํƒ์—์„œ spring_test ์„ ํƒ ํ›„ ํ™•์ธ ๋ฒ„ํŠผ ํด๋ฆญ

์•„ํ‹ฐํŒฉํŠธ ์ถ”๊ฐ€

spring_test ๋ชจ๋“ˆ ์„ ํƒ ํ›„ ํ™•์ธ ๋ฒ„ํŠผ ํด๋ฆญ!

์ดํ›„ ์ ์šฉ ๋ฒ„ํŠผ ํด๋ฆญํ•˜๋ฉด

web/WEB-INF/web.xml ํŒŒ์ผ ์ƒ์„ฑ ๋จ

4. web.xml ์„ค์ •

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/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>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
 </servlet-mapping>

ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด param-value์— ๋นจ๊ฐ„์ƒ‰ ๊ธ€์”จ๋กœ ์—๋Ÿฌํ‘œ์‹œ๊ฐ€ ๋‚˜๋Š”๋ฐ ์ด๋Š” ํ•ด๋‹น ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

web\WEB-INF\spring ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  applicationContext.xml, dispatcher-servlet.xml ์ด๋ผ๋Š” ์ด๋ฆ„์˜ spring config ํŒŒ์ผ 2๊ฐœ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

dispatcher-servlet.xml ์— ๋‹ค์Œ ์ฝ”๋“œ ์ถ”๊ฐ€

<mvc:annotation-driven/>

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

<context:component-scan base-package="com.it.spring_test"/>

์ด ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด xml ํƒœ๊ทธ์— ๋นจ๊ฐ„์ƒ‰ ๊ธ€์”จ์™€ ์ค„๊ณผ ํ•จ๊ป˜ ์—๋Ÿฌ ํ‘œ์‹œ๊ฐ€ ๋‚œ๋‹ค.

์ด๋•Œ IntelliJ์˜ ๊ธฐ๋Šฅ์„ ์ด์šฉํ•ด xml namespace๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ํŽธํ•˜๋‹ค.

์‚ฌ์ง„๊ณผ ๊ฐ™์€ ํŒ์—…์ด ๋œจ๊ฑฐ๋‚˜ ์—๋Ÿฌ ํ‘œ์‹œ๊ฐ€ ๋‚œ ์ฝ”๋“œ์— ์ปค์„œ๋ฅผ ๋‘๊ณ  Alt + Enter๋ฅผ ๋ˆŒ๋Ÿฌ๋ณด์ž.

๊ทธ๋Ÿผ ์ž๋™์œผ๋กœ xmlns:mvc ๊ฐ€ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. context namespace๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

context์˜ spring_test๋Š” ์•„๋ž˜์˜ ์ปจํŠธ๋กค๋Ÿฌ ์ƒ์„ฑ ์‹œ ๊ฒฝ๋กœ ์ƒ์„ฑํ•˜๋ฉด ์—๋Ÿฌ ์‚ฌ๋ผ์ง

ํŒŒ์ผ ์ถ”๊ฐ€ ํ›„ module ์—์„œ Spring ์ถ”๊ฐ€

5. ํ™”๋ฉด ์ถ”๊ฐ€

5-1 Controller ์ถ”๊ฐ€

it ํŒจํ‚ค์ง€ ์•„๋ž˜์— spring_test ๊ฒฝ๋กœ ์ƒ์„ฑ ํ›„ ํ•ด๋‹น ๊ฒฝ๋กœ์— HomeController.java ํŒŒ์ผ ์ƒ์„ฑ

@Controller
public class HomeController {
    @RequestMapping("/")
    public String index(Model model){
        model.addAttribute("data", "Hello, Spring from IntelliJ! :)");
        return "index";
    }
}

์ปจํŠธ๋กค๋Ÿฌ ๋‚ด์šฉ ๋ณ€๊ฒฝ

5-2 view ์ƒ์„ฑ

WEB-INF ์•„๋ž˜์— views ํŒจํ‚ค์ง€ ์ƒ์„ฑ ํ›„ ํ•ด๋‹น ๊ฒฝ๋กœ์— index.jsp ์ƒ์„ฑ

6. ํ†ฐ์บฃ ์„ค์ •

Spring 6.0, Boot 3.0์—์„œ ๋‹ฌ๋ผ์ง€๋Š” ์ 

Spring 5.x -> 6.0 ๋‹ฌ๋ผ์ง€๋Š” ์ 

  • Java 17๊ธฐ๋ฐ˜์œผ๋กœ ๋ณ€๊ฒฝ

  • ์ผ๋ถ€ Java EE API ์ง€์› ์ข…๋ฃŒ

  • XML์ด ์ ์ฐจ์ ์œผ๋กœ Spring์—์„œ๋Š” ์‚ฌ๋ผ์ง€๊ฒŒ ๋  ๊ฒƒ

  • RPC ์ง€์› ์ข…๋ฃŒ

  • ์ƒˆ๋กœ์šด AOT ์—”์ง„ ๋„์ž… (๋ฐ‘์— ์„ค๋ช… ์ถ”๊ฐ€)

  • @Inject ๊ฐ™์€ JSR์—์„œ ์ง€์›ํ•˜๋˜ ์–ด๋…ธํ…Œ์ด์…˜๋“ค์ด jakarta.annotation ํŒจํ‚ค์ง€์˜ ์–ด๋…ธํ…Œ์ด์…˜์œผ๋กœ ๋ณ€๊ฒฝ

  • HttpMethod๊ฐ€ enum์—์„œ class๋กœ ๋ณ€๊ฒฝ

  • Jakarta EE 9+๋กœ์˜ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์œผ๋กœ ์ธํ•œ ๋ณ€๊ฒฝ

    • Hibernate ORM 5.6.x ๋ฒ„์ „๋ถ€ํ„ฐ hibernate-core-jakarta ์‚ฌ์šฉ

    • javax.persistence์—์„œ jakarta.persistence๋กœ ๋ณ€๊ฒฝ

    • Tomcat 10, Jetty 11, Undertow 2.2.14 (undertow-servlet-jakarta๋„ ํฌํ•จ)์œผ๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ ํ•„์š”

    • javax.servlet์—์„œ jakarta.servlet์œผ๋กœ ๋ณ€๊ฒฝ ํ•„์š” (import)

๊ทธ๋ž˜์„œ ํ†ฐ์บฃ ๋ฒ„์ „์„ 10 ๋ฒ„์ „์œผ๋กœ ๋ฒ„์ „์—…

ํ†ฐ์บฃ local ์ถ”๊ฐ€ ํ›„ ์„ค์ •

VM option ๋ฐ port ์„ค์ •

๋ฐฐํฌ ํƒญ์—์„œ ์•„ํ‹ฐํŒฉํŠธ ์ถ”๊ฐ€ ํ›„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํ…์ŠคํŠธ ์ˆ˜์ •

7. ์‹คํ–‰

Last updated