Skip to content

alperkurtul/spring-boot-starter-firebase-realtime-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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...

About

RELEASED version -- An Easy Way to Access Firebase Realtime Database in Spring Boot

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages