Spring

Spring, Spring Boot 기본 구조

greenyellow-s 2025. 3. 13. 11:12
728x90
반응형

Spring Boot 기본 구조

 

your-project/
│
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── example/
│   │   │           └── yourproject/
│   │   │               ├── YourProjectApplication.java  <-- 애플리케이션 시작점
│   │   │               ├── controller/                <-- REST API 컨트롤러들
│   │   │               ├── service/                   <-- 비즈니스 로직
│   │   │               ├── repository/                <-- 데이터 접근 계층
│   │   │               └── model/                     <-- 엔티티, DTO 등
│   │   └── resources/
│   │       ├── application.properties or application.yml  <-- 설정 파일
│   │       ├── static/                           <-- 정적 리소스 (HTML, CSS, JS 등)
│   │       ├── templates/                        <-- 템플릿 파일 (Thymeleaf 등)
│   │       └── application-dev.properties        <-- 환경별 설정 파일
│   └── test/
│       └── java/
│           └── com/
│               └── example/
│                   └── yourproject/
│                       └── YourProjectApplicationTests.java  <-- 테스트 클래스
├── pom.xml or build.gradle  <-- 빌드 설정 파일 (Maven 또는 Gradle)
└── .gitignore               <-- Git ignore 파일

 

 

 


👀 Gradle 기본 설정

보통 MVNRepository 사이트에서 필요한 의존성 검색해서 가져오면 된다.

https://mvnrepository.com/

 

 

 

✔️ Spring Boot 기본 의존성

 dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-web'  // Spring Boot Starter Web
  implementation "org.springframework.boot:spring-boot-starter-web-services"
  implementation 'org.springframework.boot:spring-boot-starter-security'  // Spring Security
  
  implementation 'org.springframework.boot:spring-boot-starter-logging'  // 로깅 (Logback 사용)
  implementation 'org.springframework.boot:spring-boot-starter-actuator'  // 액추에이터 (모니터링)
  implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'  // Thymeleaf 템플릿 엔진

  testImplementation 'org.springframework.boot:spring-boot-starter-test'  // 테스트 라이브러리
}

 

 

✔️ 데이터베이스 의존성

implementation 'mysql:mysql-connector-java:8.0.33' // MySQL 연동
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'  // Spring Boot Starter Data JPA

annotationProcessor 'org.projectlombok:lombok' // lombok
compileOnly 'org.projectlombok:lombok'

 

 

 

✔️ application.properties 기본 설정

# server
server.port=8080 #서버 포트 번호
server.error.include-stacktrace=never #에러 구문 설정 - 안해도 됨
#db -- 데이터 베이스 연결
spring.datasource.url=jdbc:mysql://localhost:3306/[데이터베이스명]
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=[사용자계정]
spring.datasource.password=[비밀번호]
#jpa -- JPA 설정
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true

 

 

728x90
반응형