어노테이션 정리 Spring Boot && Quarkus JavaEE(JAX‐RS) - kuyeol/Document GitHub Wiki
Spring Boot와 Quarkus/JavaEE(JAX-RS) 어노테이션 비교
1. REST API (Controller/Resource)
[!note]
추가 인수 전달 옵션
GetMapping(키="값") 경로 등.. Post, Put, Delete 동일
Quarkus/JAX-RS(Java EE) |
Spring Boot |
설명 |
@Path("/hello") |
@RequestMapping("/hello") |
클래스/메서드의 URL 경로 지정 |
@GET |
@GetMapping |
GET 요청 처리 |
@POST |
@PostMapping |
POST 요청 처리 |
@PUT |
@PutMapping |
PUT 요청 처리 |
@DELETE |
@DeleteMapping |
DELETE 요청 처리 |
@Consumes(MediaType.JSON) |
없음 (자동) |
Spring은 @RequestBody로 자동 처리 |
@Produces(MediaType.JSON) |
없음 (자동) |
Spring은 @RestController가 JSON 반환 자동 처리 |
@PathParam("id") |
@PathVariable("id") |
URL 경로 변수 |
@QueryParam("q") |
@RequestParam("q") |
쿼리 파라미터 |
@HeaderParam("auth") |
@RequestHeader("auth") |
HTTP 헤더 값 |
(없음,JAX-RS) |
@RequestBody |
HTTP Body → 객체 매핑 (Spring에서 명시적으로 사용) |
|
@RestController |
자동으로 JSON 반환, 모든 메서드에 @ResponseBody 적용 |
2. 의존성 주입(Dependency Injection)
Quarkus/JAX-RS/Java EE |
Spring Boot |
설명 |
@Inject |
@Autowired |
객체 주입(필드, 생성자 등) |
@Singleton |
(기본값) 또는 @Scope("singleton") |
싱글턴 빈 |
@ApplicationScoped |
@Scope("singleton") |
애플리케이션 단위 싱글턴 |
@RequestScoped |
@Scope("request") |
요청(Request) 범위 빈 |
@Produces |
(대부분 불필요) |
Spring은 @Bean으로 대체 |
3. 서비스/빈 선언
[!cuation]
@Bean(name="🔤빈네임정의_현재빈이름으로메서드호출가능")
[!note]
@Service @Controller 등은 @Component 를 기능에 맞춰 구현
Quarkus/JAX-RS/Java EE |
Spring Boot |
설명 |
@ApplicationScoped |
@Service , @Component , @Repository |
빈/서비스 등록 |
@Bean (CDI) |
@Bean (Spring) |
수동 빈 등록 |
4. 예외 처리
Quarkus/JAX-RS/Java EE |
Spring Boot |
설명 |
@Provider |
@ControllerAdvice |
예외 공통 처리 |
@ExceptionMapper |
@ExceptionHandler |
예외 매핑 |
5. 트랜잭션
Quarkus/JAX-RS/Java EE |
Spring Boot |
설명 |
@Transactional |
@Transactional |
트랜잭션 적용 |
앱 시작 시 초기화
[!Note]
6. 예시 코드 비교
Quarkus/JAX-RS
@Path("/hello")
public class HelloResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Spring Boot
@RestController
@RequestMapping("/hello")
public class HelloController {
@GetMapping
public String hello() {
return "hello";
}
}
추가 팁
- Spring은 클래스에
@RestController
를 붙이면 모든 메서드가 JSON 반환(@ResponseBody)됨.
- 메서드 파라미터 매핑이 더 세분화되어 있어, URL, 쿼리, 헤더, 바디 등 원하는 위치별로 어노테이션 사용.