μ€νλ§λΆνΈ μ°μ΅
[TOC]
1. μ무κ²λ μλ μ€νλ§ λΆνΈ νλ‘μ νΈ μμ±
2. Coltroller μμ±νκΈ°
3. λ§μ΄λ°ν°μ€ μ€νλ§ λΆνΈ νλ‘μ νΈ μμ±
- Artifactλ λλ¬Έμλ λ£μ μ μλ€.
- Typeμ Gradle Projectλ₯Ό μ ννλ€.
- λ€μλ¨κ³λ‘ μ΄λνλ€.
- Dependenciesλ₯Ό μ ννλ λΆλΆμ΄λ€.
- νλ‘μνΈλ₯Ό μ΄λ―Έ μμ±ν ν μ΄λΆλΆμ λ€μ λ€μ΄κ°κ³ μΆμλ° μ§μ λ°©λ²μ λͺ¨λ₯΄κ² μ. γ γ
- κ·Έλμ νΉμ μ΄λΆλΆμ λ€μ μμ νκ³ μΆμλλ νλ‘μνΈλ₯Ό μλ‘ μμ±ν ν build.gradleνμΌμμ dependencies λΆλΆμ κ°μ Έμ€λλ‘ νμ
- λ€μλ¨κ³λ‘ μ΄λνλ€
- νλ‘μνΈλ₯Ό μ μ₯ν μνλ κ²½λ‘λ₯Ό μ ν ν Finishλ₯Ό μ ννλ€.
- νλ‘μνΈκ° μμ±λκ³ μλμ κ°μ νμ μ΄ λ¬λ€.
- μλͺ¨λ₯΄κ² μ΄μ κ·Έλ₯ OK
- νλ‘μνΈ μμ± ν λΉλλ₯Ό νλ€. μλμ κ°μ κ²°κ³Όκ° λμ¨λ€.
νμ¬ μνλ λͺ©νλ APIμμ μ νλ건λ°, ν΄λΌμ΄μΈνΈ λ¨μμ urlμ νΈμΆνλ©΄ μΉμλ²μμ ν΄λΉνλ μμ²μ μ²λ¦¬ν΄μ€μΌ νλ μμ μ νλ€. Controllerμ μ΄λ¬ν μμ²μ λν μ²λ¦¬νλ λΆλΆμ λͺ μΉνλ κ² κ°μΌλ©°, μ€νλ§λΆνΈμͺ½μμ @controllerμ΄λ μ΄λ Έν μ΄μ μ λΆμ¬μ€μΌ μ΄κ² λμνλ κ΅¬μ‘°λ‘ λμ΄μμ΄ λ³΄μ λλ€.(λνΌμ μ£μ‘)
- 컨νΈλ‘€λ¬μλ @Controllerμ΄λ μ΄λ Έν μ΄μ μ λΆμ¬μΌνλ€.
- μκ·Έλ €λ©΄ RequestMapping νμ url μμ² μ λμνμ§ μμ.
μ΄ μμ μ ν΄μ£Όλ©΄ λλμ΄ μΉμμ νΈμΆμ ν μ μκ²λλ€.
- ν¨μλ₯Ό μμ± ν @RequestMapping μ΄λ Έν μ΄μ μ λΆμ¬μ€λ€.
- λΌμ΄λΈλ¬λ¦¬λ₯Ό μΆκ°ν΄μ€μΌνλ€.
- μ΄ ν΄λΉ λΌμ΄λΈλ¬λ¦¬λ₯Ό μΆκ°νλλλΆν° λΉλ μ μΉμλ²κ° μλνλ κ² κ°μ보μΈλ€.
- ν¨μμ @ResponseBodyλ₯Ό μ²λ¦¬ν΄μ€μΌνλ€.
http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ μ¬μ΄νΈ μ°Έμ‘°
dependencies μ λ§μ΄λ°ν°μ€λ₯Ό μΆκ°
dependencies {
//λ§μ΄λ°ν°μ€ μΆκ°
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencies μΆκ°λ§ νκ³ λΉλμ μλμ κ°μ μλ¬κ° λμ΄
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
application.propertiesμ μλμ κ°μ΄ μ μ μ 보λ₯Ό μ€μ ν΄μ€μΌνλ€.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://sarang628.iptime.org:3306/TravelBuddy?characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=travelbuddy
spring.datasource.password=travelbuddy!@#
λͺ¨λΈμμ±
public class User {
int user_id;
String name;
@Override
public String toString() {
return new Gson().toJson(this);
}
}
λ§΅νΌ μμ±
@Mapper
public interface UserMapper {
@Select("Select * from User")
ArrayList<User> getAllUsers();
}
POST νλΌλ―Έν° λ°κΈ°
@PostMapping("/join")
public @ResponseBody
String join(@RequestParam("token") String token) {
return token;
}
μ°λΆν¬ λΉλ νκ²½μ ꡬμΆνλλ° 4~5μΌμ λ μ½μ§μ ν κ² κ°λ€. κ΅μ₯ν κ³ λ¨ν μκ°μ΄μλ€γ γ κ·Έλλ€ λΉλνλλ° μλ° λ²μ λ§μΆλκ² μ€μνμλ€. 9λ²μ μ΄μμΌλ‘ κ°λκΉ κ°μ λ¨Έμ μ΄ μλ(?)λ€λ μ€λ₯λ₯Ό λ±μ΄μ κ·Έ μΈμ μ¬λ¬κ°μ§ μ€λ₯λ€μ΄ μμλλ° κ³ μΉκΈ° λ°λΉ κΈ°λ‘μ ν μ μμλ€. μ€μν건 μλ° 8λ²μ μ μ μ€μΉν΄μ μ€ννλ©΄ λλ κ² μ΄μλ€.
oracle-java8-installer ν¨ν€μ§λ₯Ό μ¬μ©ν μ μμ΅λλ€. νμ§λ§ λ€λ₯Έ ν¨ν€μ§κ° μ°Έμ‘°νκ³ μμ΅λλ€.
ν΄λΉ ν¨ν€μ§κ° λλ½λμκ±°λ μ§μμ‘λ€λ λ»μ
λλ€. μλλ©΄ λ λ€λ₯Έ κ³³μμ
ν¨ν€μ§λ₯Ό λ°μμμΌ νλ κ²½μ°μΌ μλ μμ΅λλ€.
E: 'oracle-java8-installer' ν¨ν€μ§λ μ€μΉν μ μλ νλ³΄κ° μμ΅λλ€
sudo add-apt-repository ppa:webupd8team/java
ν¨ν€μ§ python-software-propertiesλ μ΄λ―Έ μ΅μ λ²μ μ
λλ€ (0.96.20.8).
λ€μ ν¨ν€μ§κ° μλμΌλ‘ μ€μΉλμμ§λ§ λ μ΄μ νμνμ§ μμ΅λλ€:
ant ant-optional ca-certificates-java default-jre-headless fonts-dejavu-extra java-common java-wrappers junit libactivation-java libantlr-java libaopalliance-java libapache-pom-java libasm-java
libasm4-java libaspectj-java libass5 libatinject-jsr330-api-java libatk-wrapper-java libatk-wrapper-java-jni libavcodec-ffmpeg-extra56 libavdevice-ffmpeg56 libavfilter-ffmpeg5 libavformat-ffmpeg56
libavresample-ffmpeg2 libavutil-ffmpeg54 libbcel-java libbcpg-java libbcprov-java libblas-common libbluray1 libbonobo2-0 libbonobo2-common libboost-program-options1.58.0 libboost-thread1.58.0
libbsf-java libbsh-java libbz2-dev libcapnp-0.5.3 libcdi-api-java libcglib-java libcglib3-java libchromaprint0 libclassworlds-java libcommons-cli-java libcommons-codec-java
libcommons-collections3-java libcommons-compress-java libcommons-dbcp-java libcommons-httpclient-java libcommons-io-java libcommons-lang-java libcommons-lang3-java libcommons-logging-java
libcommons-net-java libcommons-net2-java libcommons-parent-java libcommons-pool-java libdom4j-java libdoxia-core-java libecj-java libeclipse-aether-java libeclipse-jdt-core-java libel-api-java
libexpat1-dev libfelix-osgi-obr-java libgeronimo-annotation-1.3-spec-java libgeronimo-ejb-3.2-spec-java libgeronimo-interceptor-3.0-spec-java libgeronimo-jms-1.1-spec-java
libgeronimo-jta-1.1-spec-java libgeronimo-validation-1.0-spec-java libgif7 libgnome-2-0 libgnome2-common libgnomevfs2-0 libgnomevfs2-common libgoogle-gson-java libgoogle-perftools4 libgsoap8
libgtkglext1 libguava-java libguice-java libhamcrest-java libhardware2 libhawtjni-runtime-java libhttpclient-java libhttpcore-java libhybris libhybris-common1 libjansi-java libjansi-native-java
libjarjar-java libjatl-java libjaxb-api-java libjaxen-java libjaxp1.3-java libjcifs-java libjcip-annotations-java libjcommander-java libjcsp-java libjdepend-java libjdom1-java libjdom2-java
libjformatstring-java libjline2-java libjna-java libjna-jni libjsch-java libjsoup-java libjsp-api-java libjsr166y-java libjsr305-java libjzlib-java libkryo-java libkxml2-java libllvm4.0 libllvm5.0
liblog4j1.2-java liblogback-java liblua5.1-0 libmad0 libmail-java libmaven-archiver-java libmaven-parent-java libmaven-resolver-java libmaven-shared-utils-java libmaven2-core-java libmaven3-core-java
libmedia1 libmimic0 libminlog-java libnative-platform-java libnative-platform-jni libncurses5-dev libnekohtml-java libnetty-3.9-java libobjenesis-java libopencv-calib3d2.4v5 libopencv-contrib2.4v5
libopencv-core2.4v5 libopencv-features2d2.4v5 libopencv-flann2.4v5 libopencv-highgui2.4v5 libopencv-imgproc2.4v5 libopencv-legacy2.4v5 libopencv-ml2.4v5 libopencv-objdetect2.4v5 libopencv-video2.4v5
libopenjpeg5 liborbit-2-0 libosgi-annotation-java libosgi-core-java libosgi-foundation-ee-java libpcrecpp0v5 libplexus-ant-factory-java libplexus-archiver-java libplexus-bsh-factory-java
libplexus-cipher-java libplexus-classworlds-java libplexus-classworlds2-java libplexus-cli-java libplexus-component-annotations-java libplexus-component-metadata-java libplexus-container-default-java
libplexus-container-default1.5-java libplexus-containers1.5-java libplexus-interactivity-api-java libplexus-interpolation-java libplexus-io-java libplexus-sec-dispatcher-java libplexus-utils-java
libplexus-utils2-java libpolyglot-maven-java libpostproc-ffmpeg53 libqdox-java libqdox2-java libreflectasm-java librhino-java librpm3 librpmbuild3 librpmio3 librpmsign3 libschroedinger-1.0-0
libservlet-api-java libservlet3.0-java libservlet3.1-java libsisu-inject-java libsisu-plexus-java libslf4j-java libsnappy-java libsnappy-jni libsodium18 libspring-aop-java libspring-beans-java
libspring-context-java libspring-core-java libspring-expression-java libspring-instrument-java libsrtp0 libswresample-ffmpeg1 libswscale-ffmpeg3 libtbb2 libtcmalloc-minimal4 libtext-unidecode-perl
libtinfo-dev libtomcat7-java libtomcat8-java libtomcat9-java libv8-3.14.5 libva1 libwagon-file-java libwagon-ftp-java libwagon-http-java libwagon-http-shaded-java libwagon-java
libwagon-provider-api-java libwebpdemux1 libwebsocket-api-java libwildmidi1 libx264-148 libx265-79 libxalan2-java libxbean-java libxbean-reflect-java libxerces2-java libxml-commons-external-java
libxml-commons-resolver1.1-java libxom-java libxpp2-java libxpp3-java libxstream-java libxz-java libyaml-cpp0.5v5 libyaml-snake-java lua-lpeg m4 openjdk-11-jre-headless oxideqt-codecs-extra
qml-module-qtwebkit ruby2.3 snapd-login-service testng tex-common texinfo xserver-xorg-input-evdev-hwe-16.04 xserver-xorg-input-synaptics-hwe-16.04 xserver-xorg-legacy-hwe-16.04
xserver-xorg-video-amdgpu-hwe-16.04 xserver-xorg-video-qxl-hwe-16.04 xserver-xorg-video-vesa-hwe-16.04
Use 'sudo apt autoremove' to remove them.
java
Command 'java' not found, but can be installed with:
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless
- rsa ν€ μμ±νκΈ°
ssh-keygen -t rsa
-
.ssh/id_rsa.pub μμ μλ κ°μ 볡μ¬.
-
μ격 μλ²μ μ μ ν .ssh/authorized_keys(μμΌλ©΄ μμ±) μμ 볡μ¬ν κ°μ λ£μΌλ©΄λ¨
- μ΄λ―Έ λ±λ‘λκ² μλλ° κ·Έλ₯ μν°μΉλ€μ λ€μ λΌμΈμ λΆμ¬λ£μΌλκΉ μ λμλ¬λ€.
MariaDB [(none)]> create database green_cloud
-> ;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user "green_cloud"@"%" identified by "green_cloud!@#"
-> ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on green_cloud.* to "green_cloud"@"%";
Query OK, 0 rows affected (0.00 sec)