๐Ÿ’ป ๊ณต๋ถ€ ๊ธฐ๋ก/๐Ÿƒ Spring

Spring Boot/VSC | New Project

  • -

Java ๋ฅผ ๋ฐฐ์šฐ๋˜ ์ค‘ ์—ฌ๋Ÿฌ๊ฐ€์ง€ IDE ๋ฅผ ๊ฒฝํ—˜ํ•˜๊ณ  VSC(Visual Studio Code) ์—๋„ Java/Spring ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•ด์„œ ์‚ฌ์šฉํ•ด๋ดค๋‹ค.

 

VSC ์„ค์น˜

Java/Spring Boot in Visual Studio Code

 

Spring Boot support in Visual Studio Code

Spring Boot extensions for Java developer using Visual Studio Code editor.

code.visualstudio.com

์œ„ ๋งํฌ๋ฅผ ํƒ€๊ณ  ๊ฐ€๋ฉด ํ•„์š”ํ•œ ์„ค์น˜ํŒฉ๊ณผ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ• ๋“ฑ ์˜์ƒ๊ณผ ํ•จ๊ป˜ ์„ค๋ช…์ด ๋˜์–ด์žˆ๋‹ค.

(๋Œ€์ถฉ ์ƒ๋žตํ•˜๊ฒ ๋‹ค๋Š” ์†Œ๋ฆฌ)

 

์‹คํ–‰ | ๊ธฐ๋ณธ๊ฐ’ ํ™”๋ฉด

ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ฐ„๋‹จํžˆ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ์กฐ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

VSC๋Š” ์นœ์ ˆํ•˜๊ฒŒ Run ๋„ ํ‘œ์‹œํ•ด์ค€๋‹ค.

 

Run ์„ ํ•˜๊ฒŒ ๋˜๋ฉด์€ localhost:8080 ์„œ๋ฒ„๊ฐ€ ์‹คํ–‰๋˜๊ณ 

ํ•˜์–—๊ฒŒ ์งˆ๋ฆฐ ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๊ฐ€ ๋‚˜์˜จ๋‹ค.

๋Œ€์ถฉ ๊ฒ€์ƒ‰ํ•ด์„œ ์ฐพ์•„๋ดค๋‹ค.

๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ํ™”๋ฉด์„ ๋‚˜ํƒ€๋‚ด์ค„ ํ™”๋ฉด, ์ฆ‰ html(jsp ๋“ฑ) ์ด ์—†์–ด์„œ ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๋กœ ๋Œ€์ฒด๋˜์–ด ๋‚˜์˜ค๋Š” ๊ฒƒ์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

๊ทธ๋Ÿผ ๊ธฐ๋ณธ๊ฐ’ html ์„ ์„ค์ •ํ•ด์ฃผ์ž.

 

์‹คํ–‰ | HTML

์šฐ์„  html ์˜ ํŒŒ์ผ ๊ฒฝ๋กœ๋Š” src\main\resources\static ์ด๋ฉฐ, static ์•ˆ์— index.html ์„ ์ƒ์„ฑํ•ด์ค€๋‹ค.

src\main\resources\static

 

์ด๋ฆ„์€ ๊ผญ index ๋กœ ๋ช…๋ช…ํ•ด์ค€๋‹ค.

์ƒ์„ฑ๋œ html ์—์„œ !(๋Š๋‚Œํ‘œ) ๋ฅผ ์ž…๋ ฅ ํ›„ ์—”ํ„ฐ๋ฅผ ๋ˆ„๋ฅด๋ฉด html ๊ธฐ๋ณธ ํฌ๋ฉง์œผ๋กœ ์ž…๋ ฅํ•ด์ค€๋‹ค.

 

ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•˜๊ณ , ์ €์žฅ ํ›„ 'Run' ๋ฅผ ๋‹ค์‹œ ํ•œ๋‹ค.

MVMT!!

 

์žฌ์‹คํ–‰ํ•œ ์ฃผ์†Œ๋กœ ์ž…๋ ฅํ•ด์„œ ๋ณด๋ฉด์€,

์งœ์ž”!

 

์ด์ œ localhost:8080 ์˜ ๊ธฐ๋ณธ๊ฐ’ ํ™”๋ฉด์€ index.html ๋กœ ์„ค์ •๋˜์—ˆ๋‹ค.

 

์‹คํ–‰2 | Controller ํ…Œ์ŠคํŠธ

์ƒˆ๋กœ ์ƒ์„ฑํ•œ ์ž๋ฐ” ํด๋ž˜์Šค๋ฅผ @RequestMapping ์ฃผ์†Œ ๊ฒฝ๋กœ๋กœ ์‹คํ–‰์‹œํ‚ค๊ณ  ์‹ถ๋‹ค.

/home ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์„œ ์ฝ˜์†”์— print๋ฌธ์ด ์ถœ๋ ฅ๋˜๋„๋ก ์ž‘์„ฑํ–ˆ๋‹ค.

 

Run ์œผ๋กœ ์‹คํ–‰ํ•˜๋ฉด,

๋‹น์—ฐํžˆ ์—๋Ÿฌ๊ฐ€ ๋‚˜์˜จ๋‹ค.

 

์—๋Ÿฌ ๋ฉ”์„ธ์ง€ ๋ฐ‘์— ํžŒํŠธ๋ฅผ ํŒํŒ ์ œ๊ณตํ•ด์ฃผ๊ณ  ์žˆ๋Š”๋ฐ,

Circular view path [home]: would dispatch back to the current handler URL [/home] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
jakarta.servlet.ServletException: Circular view path [home]: would dispatch back to the current handler URL [/home] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

 

๋ฒˆ์—ญํ•ด๋ณด๋ฉด์€

์›ํ˜• ๋ทฐ ๊ฒฝ๋กœ [home]: ํ˜„์žฌ ํ•ธ๋“ค๋Ÿฌ URL [/home]๋กœ ๋‹ค์‹œ ๋””์ŠคํŒจ์น˜๋ฉ๋‹ˆ๋‹ค. View Resolver ์„ค์ •์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค!
(ํžŒํŠธ: ์ด๋Š” ๊ธฐ๋ณธ ๋ทฐ ์ด๋ฆ„ ์ƒ์„ฑ์œผ๋กœ ์ธํ•ด ์ง€์ •๋˜์ง€ ์•Š์€ ๋ทฐ์˜ ๊ฒฐ๊ณผ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)
์ž์นด๋ฅดํƒ€.์„œ๋ธ”๋ฆฟ.์„œ๋ธ”๋ฆฟ ์˜ˆ์™ธ: ์›ํ˜• ๋ทฐ ๊ฒฝ๋กœ [home]: ํ˜„์žฌ ํ•ธ๋“ค๋Ÿฌ URL [/home]๋กœ ๋‹ค์‹œ ๋””์ŠคํŒจ์น˜๋ฉ๋‹ˆ๋‹ค. View Resolver ์„ค์ •์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค!
(ํžŒํŠธ: ์ด๋Š” ๊ธฐ๋ณธ ๋ทฐ ์ด๋ฆ„ ์ƒ์„ฑ์œผ๋กœ ์ธํ•ด ์ง€์ •๋˜์ง€ ์•Š์€ ๋ทฐ์˜ ๊ฒฐ๊ณผ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)

 

์š”์•ฝํ•˜์ž๋ฉด View Resolver ์„ค์ •์„ ํ•ด์ค˜์•ผํ•  ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

๊ฒ€์ƒ‰๊ฒ€์ƒ‰์„ ํ†ตํ•ด์„œ ๋ฐฉ๋ฒ•์„ ์ฐพ์•˜๋‹ค.

 

์‹คํ–‰2 | application.properties

stackoverflow

 

Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error

I'm trying to make "hello world" application with gradle, spring boot and spring mvc with the simplest view resolver and html. I started from the thymeleaf spring boot example and I just wanted to

stackoverflow.com

 

์ฐพ์•„๋ณธ ๋ฐฉ๋ฒ• ์ค‘์—์„œ ๋‚˜๋Š” application.properties ์—์„œ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฒดํƒํ–ˆ๋‹ค.

๊ฐ„ใ…ก๋‹จ

 

 

๋ฐ”๋กœ ๋„ฃ๊ณ  ์ €์žฅ, ์žฌ์‹คํ–‰

 

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

 

์ด๋ ‡๊ฒŒ 500 ์—๋Ÿฌ์—์„œ 404 ์—๋Ÿฌ๋กœ ๋ฐ”๋€Œ์—ˆ๋‹ค.

๋ฐ˜๊ฐ‘๋‹ค ์—๋Ÿฌ

 

์ด์ œ ์ฝ˜์†”์„ ํ™•์ธํ•ด๋ณด๋ฉด,

์ด๊ฒƒ์€ ํ…Œ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค. / ์ด๊ฒƒ์€ ์ง‘์ž…๋‹ˆ๋‹ค.

 

์ •์ƒ์ ์œผ๋กœ ์ฝ˜์†”์— ํ™•์ธ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์žผ๋ฐŒ๋‹ค ^^

 

์ด์ œ ๋ง˜๊ป ์ฝ”๋”ฉ ํ•ด์•ผ์ง€.

'๐Ÿ’ป ๊ณต๋ถ€ ๊ธฐ๋ก > ๐Ÿƒ Spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Spring | REST API ์ˆ™์ œ  (0) 2023.01.16
Spring MVC | Web Application  (0) 2023.01.13
Spring/Mybatis | foreach(bulk insert)  (0) 2023.01.09
Spring/Mybatis | keyProperty  (0) 2023.01.09
Spring/Mybatis | ๊ณ ์ฐฐ #{}  (0) 2023.01.03
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.