0 day streak
java / beginner
Snippet

Creating a Service Layer

The @Service annotation is a specialization of @Component used to mark classes that hold business logic. This helps in separating logic from the controller layer.

snippet.java
java
1
2
3
4
5
6
@Service
public class UserService {
public String getGreeting(String name) {
return "Hello, " + name;
}
}
spring
Breakdown
1
@Service
Registers the class as a service bean in the Spring context, typically for business logic.
2
public String getGreeting
A standard method containing the specific logic needed by the application.