springbootspring
Spring Boot 정리 - 실무 서비스 구조와 핵심 개념
조회 0
Spring Boot는 Spring 기반 애플리케이션을 빠르게 시작하고 운영할 수 있도록 도와주는 프레임워크입니다.
복잡한 XML 설정 없이, 스타터 의존성과 자동 설정(auto configuration)으로 대부분의 기본 구성을 대신해 줍니다.
1. 프로젝트 구조
가장 기본적인 Spring Boot 프로젝트 구조는 다음과 같습니다.
src
└ main
├ java
│ └ com.example.demo
│ ├ DemoApplication.kt(or .java)
│ ├ controller
│ ├ service
│ └ repository
└ resources
├ application.yml
└ static / templates
DemoApplication:@SpringBootApplication이 붙은 진입점controller: HTTP 요청/응답 진입 지점service: 비즈니스 로직repository: DB 접근 레이어(JPA, MyBatis 등)
2. REST API 기본 예제 (Kotlin)
@RestController
@RequestMapping("/api/users")
class UserController(
private val userService: UserService
) {
@GetMapping
fun getUsers(): List<UserResponse> =
userService.getUsers()
}
@Service
class UserService(
private val userRepository: UserRepository
) {
fun getUsers(): List<UserResponse> =
userRepository.findAll()
.map { UserResponse.from(it) }
}
interface UserRepository : JpaRepository<UserEntity, Long>
- Spring Boot는 위와 같은 패턴을 기준으로 자동으로 Bean을 등록하고, 의존성 주입(DI)을 처리합니다.
3. 설정 파일과 프로필
application.yml또는application.properties에 환경 설정을 정의- 를 사용해 , , 등을 분리