๐โโ๏ธ Quick Start
๋น ๋ฅด๊ฒ Sprout๋ฅผ ์คํํด๋ณด์ธ์.
์ฌ์ ์๊ตฌ์ฌํญโ
- Java 21+ (๊ฐ์ ์ค๋ ๋ ๋ฐ ์ต์ ์ธ์ด ๊ธฐ๋ฅ ํ์)
- Gradle (ํ๋ก์ ํธ ๋น๋์ฉ)
1. ํด๋ก ๋ฐ ๋น๋โ
$ git clone https://github.com/yyubin/sprout.git
$ cd sprout && ./gradlew build
2. ์ ํ๋ฆฌ์ผ์ด์ ์คํโ
Java 21 ๋ชจ๋ ์๊ตฌ์ฌํญ
CGLIB ํ๋ก์๋ ๊น์ ๋ฆฌํ๋ ์ ์ ์ํด ์ถ๊ฐ ๋ชจ๋ ์ ๊ทผ ํ๋๊ทธ๊ฐ ํ์ํฉ๋๋ค.
$ java \
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \
--add-opens=java.base/java.io=ALL-UNNAMED \
--add-opens=java.base/java.util=ALL-UNNAMED \
-jar build/libs/sprout.jar
ํ
์๋ฒ ๋ชจ๋์ ์ค๋ ๋ ๋ชจ๋ธ์ ๋ช
๋ น์ค ์ธ์๊ฐ ์๋ application.yml
์ ํตํด ๊ตฌ์ฑ๋ฉ๋๋ค.
3. ์ฒซ ๋ฒ์งธ ์ ํ๋ฆฌ์ผ์ด์ โ
๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์ ํด๋์คโ
@ComponentScan("com.example.app")
public class DemoApplication {
public static void main(String[] args) throws Exception {
SproutApplication.run(DemoApplication.class);
}
}
๊ฐ๋จํ ์ปจํธ๋กค๋ฌโ
@Controller
@RequestMapping("/api")
public class HelloController {
private final GreetingService service;
public HelloController(GreetingService service) {
this.service = service;
}
@GetMapping("/hello/{id}")
public MessageDto hello(@PathVariable Long id) {
return new MessageDto(service.greet(id));
}
@PostMapping("/users")
public ResponseEntity<User> createUser(@RequestBody CreateUserRequest request) {
User user = service.createUser(request);
return ResponseEntity.ok(user);
}
}
AOP๋ฅผ ์ฌ์ฉํ ์๋น์คโ
@Service
public class GreetingService {
public String greet(Long id) {
return "์๋
ํ์ธ์, ์ฌ์ฉ์ " + id + "๋!";
}
public User createUser(CreateUserRequest request) {
// ๋น์ฆ๋์ค ๋ก์ง ๊ตฌํ
return new User(request.getName(), request.getEmail());
}
}
AOP Aspectโ
@Aspect
public class LoggingAspect {
@Around(pointcut = "com.example.app..*Service.*")
public Object logExecutionTime(ProceedingJoinPoint pjp) throws Throwable {
long startTime = System.nanoTime();
try {
return pjp.proceed();
} finally {
long duration = (System.nanoTime() - startTime) / 1_000;
System.out.printf("%s ์คํ ์๊ฐ: %d ยตs%n",
pjp.getSignature().toLongName(), duration);
}
}
}
4. ๊ตฌ์ฑ ์ค์ โ
src/main/resources/application.yml
ํ์ผ์ ์์ฑํ์ธ์.
author: ๋น์ ์-์ด๋ฆ
server:
execution-mode: hybrid # nio | hybrid | blocking
thread-type: virtual # virtual | platform
thread-pool-size: 150 # thread-type = platform์ผ ๋๋ง ์ฌ์ฉ
sprout:
database:
url: jdbc:mysql://localhost:3306/myapp
username: root
password: your-password
5. ์ ํ๋ฆฌ์ผ์ด์ ํ ์คํธโ
์คํ ํ ์๋ํฌ์ธํธ๋ฅผ ํ ์คํธํด๋ณด์ธ์.
# GET ์์ฒญ
curl http://localhost:8080/api/hello/123
# POST ์์ฒญ
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"name": "ํ๊ธธ๋", "email": "hong@example.com"}'
๋ค์ ๋จ๊ณ๋?โ
- ๐๏ธ ์ํคํ ์ฒ ์ดํดํ๊ธฐ - Sprout์ ์๋ ์๋ฆฌ ์ดํด
๋ฌธ์ ๊ฐ ๋ฐ์ํ๋์?โ
- ์ผ๋ฐ์ ์ธ ๋ฌธ์ ๋ค ์ฐพ์๋ณด๊ธฐ
- ์ปค๋ฎค๋ํฐ ํ ๋ก ์ ์ฐธ์ฌํ๊ธฐ