I have a springboot application which I’m hosting on my own home server. I have sql database setup on the same.

And for front end I’m planning to use android for initial testing phase then shift it to flutter.

I was wonder how do I send notifications from my spring boot to my front end application. I have seen a few articles on how to send it through fire base but I was wondering if there’s another way of achieving the same without using an external service.

I have setup my server running Ubuntu on on 3 pc which loadbalances my app and want to use one of them to send push notifications.

Solution 1: Nilesh Senta

Please follow the below steps

  1. Install Dependency (Gradle/ Maven)


implementation 'com.google.firebase:firebase-admin:8.1.0'


  1. Add firebase-service-account.json file


  1. Open MainApplication java class
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;

public class BackendApplication {
    public static void main(String[] args) {
        SpringApplication.run(BackendApplication.class, args);

    FirebaseMessaging firebaseMessaging() throws IOException {
        GoogleCredentials googleCredentials = GoogleCredentials
                .fromStream(new ClassPathResource("firebase-service-account.json").getInputStream());
        FirebaseOptions firebaseOptions = FirebaseOptions
        FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions, "YOUR APP NAME");
        return FirebaseMessaging.getInstance(app);

  1. Create Service

import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import org.springframework.stereotype.Service;

public class FirebaseMessagingService {

    private final FirebaseMessaging firebaseMessaging;

    public FirebaseMessagingService(FirebaseMessaging firebaseMessaging) {
        this.firebaseMessaging = firebaseMessaging;

    public void sendNotification(String title, String body, String token) throws FirebaseMessagingException {

        Notification notification = Notification

        Message message = Message
//              .putAllData(note.getData())
  1. Usage of service inside controller
    private FirebaseMessagingService firebaseService;

    public void sendPushMessage(){
        firebaseService.sendNotification("Notification title", "Notification Text", "Receiver device token");