티스토리 뷰
구글에 start.spring.io 검색 후 사이트 접속
초기 화면
버전은 매번 바뀐다.
좌측 설정
그래들 또는 메이븐 선택, 스프링 부트 버전과 자바 버전 선택 등등 알아서 선택하고
Artifact와 Name에 프로젝트명을 입력해준다.
우측 설정
각자 개발 환경에 맞게 추가하는데,
난 MySQL Driver, Spring Security 등등을 사용하기 위해 추가적으로 넣었다.
설정 마친 후 하단 GENERATE 클릭
폴더 다운
바탕화면에 압축 풀기
이클립스에서 스프링 스타터 프로젝트 생성
방금 만든 폴더와 똑같은 이름으로 생성 후,
해당 workspace 폴더에 아까 다운받은 폴더 덮어씌우기
이후 refresh 하면 아까 설정한 폴더대로 프로젝트 생성 완료
application.properties는 application.yml로 바꾸기
이클립스에선 yml로 주로 쓰고, 인텔리제이에선 properties로 주로 씀
이건 내 취향이다.
application.yml 파일 작성 - MySQL 정보 등
#################################
# Port Number
#################################
server:
port: 80
servlet:
encoding:
charset: UTF-8
enabled: true
force: true
spring:
banner:
location: banner/banner.txt
application:
name: PipProject
devtools:
livereload:
enabled: true
restart:
enabled: true
thymeleaf:
cache: false
encoding: UTF-8
#################################
# MySQL Setting
#################################
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/bootex?serverTimezone=UTC #bootex는 DB 이름
username: root
password: 1234
#################################
# JPA Setting
#################################
jpa:
open-in-view: true
hibernate:
ddl-auto: update #update로 바꾸면 값이 보관이 됨, 사라지지 않음
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
show-sql: true
properties:
hibernate:
format_sql: true
database-platform: org.hibernate.dialect.MySQL8Dialect
jackson:
serialization:
fail-on-empty-beans: false
###############################
# Security User
###############################
security:
user:
name: test@test.com
password: 1111
###############################
# Log info
###############################
logging:
level:
org:
hibernate:
type:
descriptor:
sql: trace
pom.xml 작성
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>inhatc.pip.project</groupId>
<artifactId>PipProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PipProject</name>
<description>테스트 프로젝트</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>5.0.0</version>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>5.0.0</version>
<classifier>jakarta</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
이후 프로젝트 우클릭 > 메이븐 업데이트
테스트 - ①컨트롤러 작성
TestController.java
package demo.test.project.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import lombok.extern.log4j.Log4j2;
@Controller
@Log4j2
public class TestController {
@GetMapping("/test111")
public String index() {
log.info("안녕하세요? 테스트입니다.");
return "Test";
}
}
테스트 - ②html 작성
Test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>하하하하하</h1>
</body>
</html>
테스트 - ③실행
Application 우클릭 > Run As > Java Application
테스트 - ④접속
브라우저 열고 주소창에 localhost/test111 입력 시
테스트 완료.
'Spring' 카테고리의 다른 글
Spring 컨트롤러 이름 변경 후 org.springframework.beans.factory.BeanCreationException 에러 해결 방법 (1) | 2024.11.19 |
---|---|
[Spring Boot] Tmap API를 이용한 Geocoding - 위치 정보를 좌표로 반환하기 (0) | 2024.01.29 |
[Spring Boot] 파일 업로드와 섬네일 처리 (1) | 2023.10.09 |
[Spring Boot] CoolSMS API를 이용한 휴대폰 본인인증 (0) | 2023.10.09 |
- Total
- Today
- Yesterday
- 티스토리챌린지
- 노드
- docker
- tomcat
- 그리드
- 트리
- Spring
- dockerspring
- MySQL
- BigDecimal
- docker배포
- 백준
- Java
- 오블완
- 클라우드
- google cloud run
- 이클립스
- 웹스퀘어
- 백준자바
- 톰캣
- Apache
- 자바
- SpringBoot
- 백준알고리즘
- db
- docker컨테이너
- docker앱배포
- 알고리즘
- controller
- websquare
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |