Service In Spring Boot For Beginners

Service in spring boot is component where you usually place your business logic of your application. So service will be the class where mostly you will write Java code. Business logic can be anything for example, when user update profile, buying items, checkout, etc.

So here's an example of simple service in spring for user registration, login, update, and remove.

public class UserService{


private UserRepository userRepository;

public User registration(User newUser){

public User login(UserDto user){
return userRepository.findByUsername(user.getUsername());

public User update(Long id, User newUser){
User user = userRepository.findById(id).orElse(new User);

return user;


public void remove(Long id){

To make a class as a service, you add a @Service annotation, and on the above code we are auto wiring UserRepostiry which we already discuss on the previous post, please refer to:

And if there's something you need to know about spring, pleas leave a comment.


Popular posts from this blog

ASUS Battery Health Charging Software To Make Your Battery Life Longer

Flutter Button With Left Align Text and Icon

Flutter AppBar, With Icon, Title and Actions Link

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password

How To Create Spring Boot Project Using Netbeans