Skip to content

Service Module

A standalone OSGi service (business logic) that can be consumed by other modules.

  • Encapsulate reusable logic (e.g., “EmailNotificationService”).
  • Follow SOLID principles (single responsibility).
Terminal window
blade create -t service notification-service
notification-service/src/main/java/com/example/notification/NotificationService.java
@Component(service = NotificationService.class)
public class NotificationService {
public void sendEmail(String to, String subject, String body) {
// Logic to send emails
System.out.println("Email sent to: " + to);
}
}
// In another module (e.g., a portlet)
@Reference
private NotificationService _notificationService;
public void notifyUser(User user) {
_notificationService.sendEmail(
user.getEmailAddress(),
"Welcome!",
"Thanks for signing up."
);
}
  • Reusable Utilities: Logging, notifications, validations.
  • Modular Design: Decouple business logic from UI.