Firebase Cloud Messaging – Spring Server to Push Notification Example | Spring Boot

In the article Firebase Cloud Messaging – How to Subscribe TOPIC & Receive Messages | Android, we have created an Android App that can subscribe/unsubscribe specific TOPIC and receive Message Data, but we used Firebase Notification Console GUI to generate Notification. Today, we’re gonna look at way to create a Spring Boot Application Server that can make message and push notification to Android Client via Firebase.

Related Post: Firebase Cloud Messaging – XMPP Server example to receive Upstream Messages | Spring Integration

I. Project Overview

1. Architecture


2. Topic HTTP POST

Send to a single topic JavaSampleApproach:

Send to devices subscribed to topics ABC or XYZ:

This is the response:

3. Technology

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.4.RELEASE
– Spring Boot: 2.0.0.M2

4. Structure


AndroidPushNotificationsService is the service that provides send() method (with ClientHttpRequestInterceptor and RestTemplate POST request) to Firebase FCM.
WebController is a REST Controller that creates Message Data Entity and uses Service above to push Notification.

II. Practice

1. Get Server Key

Go to Settings of your Firebase Project in Firebase Console to get Server Key.

2. Create Spring Boot project

– Using Spring Tool Suite/Eclipse to create Spring Boot project.
– Add Dependencies to pom.xml file:

3. Create Push Notification Service

Remember to copy your Server Key at the first step to FIREBASE_SERVER_KEY.

4. Create Controller

5. Run & Check Result

– Config maven build:
clean install
– Run project with mode Spring Boot App.
– Open Browser, enter URL:

Look back to the Android App Client that can subscribe/unsubscribe TOPIC and receive Message:
– Android App Client in background:

– Android App Client in running foreground:

III. Source Code


By grokonez | July 10, 2017.

Last updated on July 13, 2018.

Related Posts

25 thoughts on “Firebase Cloud Messaging – Spring Server to Push Notification Example | Spring Boot”

    1. Hi jagadish,

      I haven’t tried yet, but I think it works with iOS devices because we just make HTTP POST request to Firebase Server, then it will send Notification to devices which have subscribed TOPIC.


  1. 저는 전자정부프레임웍을 사용하는데
    import org.springframework.http.HttpRequest;
    import org.springframework.http.client.ClientHttpRequestExecution;
    import org.springframework.http.client.ClientHttpRequestInterceptor;
    import org.springframework.http.client.ClientHttpResponse;
    모든게 다 임폴트가 되지 않습니다.

    1. The thing is firebase generates a unique device Id for your target device when the app is run for the first time,and is being used as the identity of the device,If the User uninstalls the app or clears the data of the app then In that case On re installing or reopening the app the device Id will differ which will not be identified by firebase to send the notification this will result in the error Not Registered

Got Something To Say:

Your email address will not be published. Required fields are marked *