Managing with Firebase Realtime Database

This library is used for accessing to the Firebase Realtime Database.

License

License

Categories

Categories

Spring Boot Container Microservices Data
GroupId

GroupId

com.github.alperkurtul
ArtifactId

ArtifactId

spring-boot-starter-firebase-realtime-database
Last Version

Last Version

1.0.5.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

Managing with Firebase Realtime Database
This library is used for accessing to the Firebase Realtime Database.
Project URL

Project URL

https://github.com/alperkurtul/spring-boot-starter-firebase-realtime-database
Source Code Management

Source Code Management

https://github.com/alperkurtul/spring-boot-starter-firebase-realtime-database

Download spring-boot-starter-firebase-realtime-database

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.alperkurtul/spring-boot-starter-firebase-realtime-database/ -->
<dependency>
    <groupId>com.github.alperkurtul</groupId>
    <artifactId>spring-boot-starter-firebase-realtime-database</artifactId>
    <version>1.0.5.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.alperkurtul/spring-boot-starter-firebase-realtime-database/
implementation 'com.github.alperkurtul:spring-boot-starter-firebase-realtime-database:1.0.5.RELEASE'
// https://jarcasting.com/artifacts/com.github.alperkurtul/spring-boot-starter-firebase-realtime-database/
implementation ("com.github.alperkurtul:spring-boot-starter-firebase-realtime-database:1.0.5.RELEASE")
'com.github.alperkurtul:spring-boot-starter-firebase-realtime-database:jar:1.0.5.RELEASE'
<dependency org="com.github.alperkurtul" name="spring-boot-starter-firebase-realtime-database" rev="1.0.5.RELEASE">
  <artifact name="spring-boot-starter-firebase-realtime-database" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.alperkurtul', module='spring-boot-starter-firebase-realtime-database', version='1.0.5.RELEASE')
)
libraryDependencies += "com.github.alperkurtul" % "spring-boot-starter-firebase-realtime-database" % "1.0.5.RELEASE"
[com.github.alperkurtul/spring-boot-starter-firebase-realtime-database "1.0.5.RELEASE"]

Dependencies

compile (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-web jar 2.2.0.RELEASE
org.json : json jar 20190722

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.2.0.RELEASE

Project Modules

There are no modules declared in this project.

An Easy Way to Access Firebase Realtime Database in Spring Boot

This project gives you the ability to access to Firebase Realtime Database. To achieve this, you just have to add some basic annotations and define a generic repository in your Spring Boot application. These are the list of methods you can use in this release(1.0.5):

  • save (@Deprecated in 1.0.5.RELEASE)
  • saveWithRandomId (added in 1.0.5.RELEASE)
  • saveWithSpecificId (added in 1.0.5.RELEASE)
  • read
  • update
  • delete

How to Apply

Configuration

Add this property in your application.properties.

firebase-realtime-database.database-url=[firebase realtime database url]

Dependencies

Primarily, you have to add spring-boot-starter-web dependency in your Spring Boot application.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Then, you have to also add this dependency in your pom.xml.

<dependency>
    <groupId>com.github.alperkurtul</groupId>
    <artifactId>spring-boot-starter-firebase-realtime-database</artifactId>
    <version>1.0.5.RELEASE</version>
</dependency>

and How to Use

  1. create a class for your Firebase Realtime Database Document
  2. annotate this class as @FirebaseDocumentPath and specify a path for your realtime database
  3. create a String property for your authentication idToken and annotate it as @FirebaseUserAuthKey
  4. create a property for the ID and annotate it with @FirebaseDocumentId
@FirebaseDocumentPath("/product")
public class Product {

    @FirebaseUserAuthKey
    private String authKey;
    
    @FirebaseDocumentId
    private String firebaseId;
    
    private String id;
    private String name;
    private BigDecimal price;

}

Then create a Repository class. This class must extend the FirebaseRealtimeDbRepoServiceImpl class.

@Repository
public class ProductRepository extends FirebaseRealtimeDbRepoServiceImpl<Product, String> {
}

At last, put @EnableFirebaseRealtimeDatabase just next to @SpringBootApplication in your main class of Spring Boot application.

@EnableFirebaseRealtimeDatabase
@SpringBootApplication
public class DemoApplication {

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

}

Demo

Here is a demo that I made for you. Demo

Releases

  • 1.0.5.RELEASE (2019-11-27)
    • BugFix : Annotated fields (@FirebaseUserAuthKey and @FirebaseDocumentId) also were being saved to Firebase Database. It is fixed.
    • save method @Deprecated
    • Instead of save method, saveWithRandomId method was added.
    • saveWithSpecificId method wad added as a new feature. By using this method, you can set specific FirebaseId of your record.

Next

I hope, I will be able to continue to add new features in the next. Don't be shy to send your advice to me. Take care...

Versions

Version
1.0.5.RELEASE
1.0.4.RELEASE
1.0.3.RELEASE
1.0.2.RELEASE
1.0.1.RELEASE
1.0.0.RELEASE