[Day 1] SpringBoot + Vue.js ๊ฐ๋ฐํ๊ฒฝ ์ธํ
by ์ค๊ทคํฑ๊ทค์ด๊ฑฐ ์ธํ ํ๋๋ฐ 3์ผ์ด ๊ฑธ๋ฆฐ ์ฌ๋์ด ์๋ค? ๋ฟ์๋น ์ (๊ทธ๊ฒ ๋์ผ ๋ ๋น ๋ ๋น ๋๋น๋๋ฐฅ)d
Vue์ SpringBoot์ ๋ฌธ์ธํ์ธ ์ฌ๋์ด ์ฐ๋ ๊ธ์ด๊ธฐ ๋๋ฌธ์ ์ฒ์๋ถํฐ ์จ๋ณด๊ณ ์ ํ๋ค.
โป์ด ๊ธ์ Window ๊ธฐ๋ฐ์ผ๋ก ์์ฑ๋์์
1. SpringBoot Settin
1-1. JDK ์ค์น
https://www.oracle.com/kr/java/
Java Software
๋น์ฉ ์ ๊ฐ, ํ์ ์ด์ง, ์ ํ๋ฆฌ์ผ์ด์ ์๋น์ค ๊ฐ์ ์ ๊ฐ๋ฅํ๊ฒ ํด์ฃผ๋ Java Software. ์ธ๊ณ 1์ ๊ฐ๋ฐ์ ํ๋ซํผ Java์ ๋ํ ๋ ๋ง์ ์ ๋ณด๋ฅผ ํ์ธํด๋ณด์ธ์.
www.oracle.com
์๋ฐ ๊ฐ๋ฐ ํ๊ฒฝ์ ๊ตฌ์ถํ๊ธฐ ์ํด JDK๋ฅผ ์ค์นํ๋ค.
1-2. ํ๊ฒฝ๋ณ์ ์ค์
JAVA_HOME (์ถ๊ฐ) : JDK๊ฐ ์ค์น๋ ๋๋ ํ ๋ฆฌ
CLASSPATH (์ถ๊ฐ) : %JAVA_HOME%\lib
PATH (ํธ์ง) : %JAVA_HOME%\bin
1-3. STS ์ค์น
Spring | Home
Cloud Your code, any cloud—we’ve got you covered. Connect and scale your services, whatever your platform.
spring.io
์์ ์์ ์ด ์ฌ์ฉํ๋ tool๊ณผ ์ด์์ฒด์ ์ ๋ง๋ ์คํํ์ผ์ ๋ค์ด๋ก๋ํ๋ค.
๋๋ ์ต์ํ Eclipse๋ก ๋ค์ด๋ก๋ ๋ฐ์๋ค.
1-4. SpringBoot Project ์์ฑ
Spring Starter Project๋ฅผ ์ ํํ์ฌ SpringBoot ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ค.
์์ ๊ฐ์ด ์ค์ ์ ์๋ฃํ์๋ค.
๊ผญ maven, gradle ๋ ์ค ํ์ผ์ ํด์ผํ๋ ๊ฒ์ ์๋๋ ์ต์ํ ๊ฒ์ผ๋ก ์ ํํ๋ฉด ๋ ๊ฒ ๊ฐ๋ค.
(์ ํ์ฌํญ)
SpringBootDevTools
Lombok
Oracle Driver
Spring Web
์ ์ ํํ์ฌ dependencies๋ฅผ ์ถ๊ฐํ๋ค. ์ฌ๊ธฐ์ ์ถํ์ ํ์ํ๋ค๋ฉด pom.xml์์ ์์์ ์ถ๊ฐํ๋ฉด ๋๊ธฐ ๋๋ฌธ์
์ด ๋จ๊ณ์์ ๊ผญ ๋ฌด์ธ๊ฐ๋ฅผ ์ถ๊ฐํด์ผํ ํ์๋ ์๋ค๊ณ ํ๋ค.
์ ํ์ ๋ค ํ๋ค๋ฉด Finish๋ฅผ ๋๋ฌ Project๋ฅผ ์์ฑํ๋ค.
2. Vue.js Setting
2-1. VSCode ์ค์น
https://code.visualstudio.com/
Visual Studio Code - Code Editing. Redefined
Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.
code.visualstudio.com
(์ ํ์ฌํญ)
VSCode๋ฅผ ์ค์น ํ, Extensions์์
Vue3 Snippets
Vetur
HTML CSS Support
๋ฅผ ์ค์นํ๋ค.
2-2. Node.js ์ค์น
https://nodejs.org/ko/download/
๋ค์ด๋ก๋
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
nodejs.org
์ด๋์๋ LTS๊ฐ ์์ ์ ์ด๊ณ ์ด๋์๋ ์ต์ ๋ฒ์ ์ด ์์ ์ ์ด๋ผ๊ณ ํ๋๋ฐ, ๋๋ LTS๋ฅผ ๋ค์ด๋ก๋ ๋ฐ์๋ค.
ํ๋ฐ Windows Installer๋ฅผ ๋๋ฌ ๋ฐ๋ก ๋ค์ด๋ก๋๋ฅผ ๋ฐ์ผ๋ฉด 64bit๊ฐ ์๋ 32bit ํ์ผ์ด ๋ค์ด๋ฐ์์ ธ์ ๋ฐ์์ 64bit ํ์ผ์ ์์ ๋ฐ์๋ค. ๋ด ์ปดํจํฐ 64bit ๋ง๋๋ฐ ์...
node.js๋ฅผ ์ค์นํ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก npm๋ ์ค์น๊ฐ ์๋ฃ ๋๋ค.
2-3. Vue-cli ์ค์น
cmd๋ฅผ ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํํ๋ค.
npm install -g @vue/cli
๋ฅผ ์ ๋ ฅํ์ฌ vue/cli๋ฅผ ์ค์นํ๋ค. ์ด ๋ -g ๋ช ๋ น์ด๋ฅผ ํตํด ์ ์ญ์ ์ผ๋ก ์ค์นํ์๊ธฐ ๋๋ฌธ์
์ค์น ๋๋ ํฐ๋ฆฌ๋ ์ค์ํ์ง ์๋ค.
2-4. Vue Project ์์ฑ
workSpace๋ฅผ Openํ๊ณ , terminal์ ์คํํ๋ค.
/* ์์ฑํ ํ๋ก์ ํธ๋ก ์ด๋ */
cd VueSpring
// Vue Project ์์ฑ
vue create vue --no-git
/*
vue create vueํ๋ก์ ํธ๋ช
git๋ฏธ์์ฑ
*/
์ ์ ๋ ฅํ๋ค.
๋๋ Vue3 Default๋ก ์์ฑํ์๋ค.
cd vue
npm run serve
ํ์ฌ ์์ฑํ vueProject๋ก ์ด๋ํ๋ค.
server run์ ํตํด์ ์ ์์ ์ผ๋ก ํ๋ก์ ํธ๊ฐ ์์ฑ๋์๋์ง ํ์ธํ๋ค.
Vue ์ด๊ธฐํ๋ฉด์ด ๋ํ๋ฌ๋ค๋ฉด,
VSCode terminal์์ Ctrl + C, y๋ฅผ ์ฐจ๋ก๋ก ์ ๋ ฅํ์ฌ server๋ฅผ offํ๋ค.
2-5. vue.config.js ์์
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
outputDir: "../src/main/resources/static",
indexPath: "index.html",
devServer: {
port: 8081,
proxy: "http://localhost:8080"
},
chainWebpack: config => {
const svgRule = config.module.rule("svg");
svgRule.uses.clear();
svgRule.use("vue-svg-loader").loader("vue-svg-loader");
}
})
outputDir : ๋น๋๋ ํ์ผ์ด ์์ฑ๋๋ ๋๋ ํ ๋ฆฌ
indexPath : ์์ฑ๋ ํ์ผ ์ค์์ ์ง์ ์ ํ์ผ
port : vue ๊ฐ๋ฐ ์๋ฒ port
proxy : SpringBoot (backend ๋ด์ฅ was ์ฃผ์)
ํ์ฌ ๋๋ SpringBoot์์ ๋ฐ๋ก port๋ฅผ ์ง์ ํ์ง ์์๊ธฐ ๋๋ฌธ์ default port์ธ 8080์ผ๋ก ์ง์ ์ด ๋์ด์๋ค.
vue ๊ฐ๋ฐ port๋ ์ด๋์๋ ๋ง์ถฐ์ผ ํ๋ค๊ณ ํ๊ณ ์ด๋์๋ ๋ค๋ฅด๊ฒ ํด์ผํ๋ค๊ณ ํ๋๋ฐ, ๋๋ ๋ค๋ฅด๊ฒ ์ง์ ํ๋ค.
๋น๋ํ์ผ ๋๋ ํ ๋ฆฌ๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด vue Project ๋ด dist ํด๋ ๋ด์ ๋น๋ํ์ผ์ด ์์ฑ๋๋ค. ํ์ง๋ง ๋๋ SpringBoot ํ๋ก์ ํธ์ ์ ์ ํ์ผ(๋น๋ํ์ผ)์ ์์ฑํด์ผ ํ๊ธฐ ๋๋ฌธ์ SpringBoot ๋ด ํด๋๋ก ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ฐ๋ก ์ง์ ํด์ค ๊ฒ์ด๋ค.
npm run build
terminal์ build ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ฌ build ํ์ผ์ ์์ฑํ๋ค.
๋น๋ํ์ผ ์์ฑ์ด ์๋ฃ๋๋ฉด ์คํ๋ง ํ๋ก์ ํธ๋ฅผ ์๋ก๊ณ ์นจํ ๋ค, ๋ด์ฅ was๋ฅผ ์คํ์ํจ๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก Vue ์ด๊ธฐํ๋ฉด์ด ๋ณด์ธ๋ค๋ฉด ์ธํ ์๋ฃ!
↓ Error: Source and destination must not be the same. ๊ฐ ๋๋ค๋ฉด ํ์ธ
module.exports = {
outputDir: "../src/main/resources/static",
indexPath: "../static/index.html",
devServer: {
proxy: "http://localhost:8080"
}
};
๋ผ๊ณ ์๋ ค์ฃผ๋ chatGPT... ํ์ง๋ง! ๋๋ ์ด๋ ๊ฒ ํ์์๋ ๋ถ๊ตฌํ๊ณ ๊ณ์ํด์ build Complete ํ ์๋ฌ๋ฅผ ๋ฑ์ด๋๋ค.

์๋ฌด๋ฆฌ ๊ตฌ๊ธ๋ง์ ํด๋ด๋ ์ ๋ฐฉ๋๊ฐ ์์๋ค๊ฐ ๊ฒฐ๊ตญ chatGPT์ ๋์์ ๋ฐ์ ํด๊ฒฐํ๋ค.
ํด๊ฒฐ๋ฐฉ๋ฒ์ outputDir / indexPath์ ๊ฒฝ๋ก๋ฅผ ๋ฌ๋ฆฌํด์ผํ๋ค๋ ๊ฒ!
์ด์ ๋ ๋ค์๊ณผ ๊ฐ๋ค.
outputDir๊ณผ indexPath๊ฐ ๊ฐ์ ๊ฒฝ์ฐ ์๋ฌ๊ฐ ๋ฐ์ํ๋ ์ด์ ๋ outputDir์ด ๋น๋๋ ํ์ผ์ด ์์ฑ๋๋ ๋๋ ํ ๋ฆฌ๋ฅผ ์๋ฏธํ๊ณ , indexPath๋ ์์ฑ๋ ํ์ผ ์ค์์ ์ง์
์ ํ์ผ์ ์๋ฏธํฉ๋๋ค. ๋ฐ๋ผ์ outputDir๊ณผ indexPath๊ฐ ๊ฐ์ ๋๋ ํ ๋ฆฌ๋ฅผ ๊ฐ๋ฆฌํค๊ฒ ๋๋ฉด ๋น๋๋ ํ์ผ์ด ์ด๋ฏธ ์์ฑ๋ ์ํ์์ ๋ค์ ๊ทธ ํ์ผ์ ๋ฎ์ด์ฐ๊ธฐ๋ฅผ ํ๋ ค๊ณ ํ๊ธฐ ๋๋ฌธ์ ๋ฐ์ํ๋ ๊ฒ์
๋๋ค.
์๋ฅผ ๋ค์ด, outputDir์ด dist์ด๊ณ , indexPath๊ฐ dist/index.html๋ก ์ค์ ๋์ด ์๋ค๊ณ ๊ฐ์ ํด ๋ด
์๋ค. ์ด ๊ฒฝ์ฐ npm run build ๋ช
๋ น์ผ๋ก Vue.js ํ๋ก์ ํธ๋ฅผ ๋น๋ํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ์ผ์ด ์ผ์ด๋ฉ๋๋ค.
dist ๋๋ ํ ๋ฆฌ๊ฐ ์์ฑ๋ฉ๋๋ค.
Vue.js ์ ํ๋ฆฌ์ผ์ด์
์ ์ปดํ์ผ๋ ํ์ผ๋ค์ด dist ๋๋ ํ ๋ฆฌ ๋ด์ ์์ฑ๋ฉ๋๋ค.
dist/index.html ํ์ผ์ด ์์ฑ๋ฉ๋๋ค.
์์ ๊ณผ์ ์์ outputDir๊ณผ indexPath๊ฐ ๊ฐ์ ๊ฒฝ์ฐ, Vue.js ์ ํ๋ฆฌ์ผ์ด์
์ ์ปดํ์ผ๋ ํ์ผ๋ค์ด ์ด๋ฏธ dist ๋๋ ํ ๋ฆฌ์ ์์ฑ๋์ด ์๊ณ , dist/index.html ํ์ผ์ ์์ฑํ๋ ค๊ณ ํ๊ฒ ๋ฉ๋๋ค. ์ด๋ ๊ฐ์ ํ์ผ์ ๋์์ผ๋ก ๋ฎ์ด์ฐ๊ธฐ๋ฅผ ์๋ํ๊ฒ ๋์ด Error: Source and destination must not be the same. ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
๋ฐ๋ผ์ outputDir๊ณผ indexPath๋ ์๋ก ๋ค๋ฅธ ๊ฐ์ ๊ฐ๋ฆฌํค๋๋ก ์ค์ ํด์ผ ํฉ๋๋ค.
๋ฐ๋ผ์ 2-5 ์ฒ๋ผ outputDir๊ณผ indexPath๋ฅผ ๋ค๋ฅด๊ฒ ์ค์ ํด์ฃผ๊ฑฐ๋,
์๋๋ฉด indexPath๋ฅผ ์ค์ ํ์ง ์๋ ๊ฒ์ด ๋ฐฉ๋ฒ์ด๋ค... ^^....๋ด 3์ผ........
'FRONTEND > VUE.JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Day 2] SpringBoot + Vue.js์ MyBatis ๋ผ์น๊ธฐ (1) | 2023.03.21 |
---|
๋ธ๋ก๊ทธ์ ์ ๋ณด
๐๐๐ซ๐๐ง ๐ฟ๐๐
์ค๊ทคํฑ๊ทค