Indicates that an annotated class is a "Service", originally defined by Domain-Driven Design (Evans, 2003) as "an operation offered as an interface that stands alone in the model, with no encapsulated state."
May also indicate that a class is a "Business Service Facade" (in the Core J2EE patterns sense), or something similar. This annotation is a general-purpose stereotype and individual teams may narrow their semantics and use as appropriate.
This annotation serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning.
출처: Spring Framework Documentation - @Service
에릭 에반스(2003)의 도메인 주도 설계(Domain-Driven Design)에서 "캡슐화된 상태 없이 모델에서 독립적으로 제공되는 인터페이스로서의 작업"으로 정의
비즈니스 서비스 퍼사드"(코어 J2EE 패턴의 의미에서)나 이와 유사한 것임을 나타낼 수 있다.
대략 이정도.. 중요한 건
비즈니스 로직 구현 : 핵심 기능 규칙 구현
트랜잭션 관리 : @Transactional 어노테이션 사용해서 관리
다른 서비스 및 리포지토리 호출해 작업 위임
예외처리 등..
출처: Spring - The Service Layer
@Service
public class OrderServiceFacade {
private final OrderRepository orderRepository;
private final PaymentService paymentService;
private final InventoryService inventoryService;
private final NotificationService notificationService;
// 생성자 주입
public OrderServiceFacade(OrderRepository orderRepository,
PaymentService paymentService,
InventoryService inventoryService,
NotificationService notificationService) {
this.orderRepository = orderRepository;
this.paymentService = paymentService;
this.inventoryService = inventoryService;
this.notificationService = notificationService;
}
@Transactional
public Order placeOrder(OrderRequest orderRequest) {
// 재고 확인
inventoryService.checkAvailability(orderRequest.getItems());
// 주문 생성
Order order = new Order(orderRequest.getItems(), orderRequest.getShippingAddress());
orderRepository.save(order);
// 결제 처리
paymentService.processPayment(order);
// 알림 발송
notificationService.sendOrderConfirmation(order);
return order;
}
// 다른 비즈니스 로직 메서드...
}