Skip to content

Latest commit

 

History

History
122 lines (88 loc) · 4.3 KB

File metadata and controls

122 lines (88 loc) · 4.3 KB

Offline Mode for Spring Boot

Spring Boot Starter provides an Offline Mode for Spring Boot application.

Quality Gate Status Maintainability Rating Reliability Rating Coverage Build

🚀 Quick start

  1. Add dependency to your project

Maven

<dependency>
    <groupId>pl.maciejkopec</groupId>
    <artifactId>offline-mode-spring-boot-starter</artifactId>
    <version>2.0.9</version>
</dependency>

Gradle

implementation 'pl.maciejkopec:offline-mode-spring-boot-starter:2.0.9'
  1. Enable Offline Mode in LEARNING mode

application.yaml

offline-mode:
  mode: learning
  enabled: true
  1. Mark method with @OfflineMode annotation
@Service
class DemoService {

    @OfflineMode
    public String demo() {
        return "test" + LocalDate.now();
    }
}
  1. Run your application. This library will capture the returned data and store serialized data in offline folder.
  2. Turn Offline Mode in SERVING mode

application.yaml

offline-mode:
  mode: serving
  enabled: true

The execution of demo() method won't happen now. Instead, the return data will be served from serialized file captured in the previous step.

See documentation for more examples.

✔️ Requirements

2.X version

  • Spring Boot 3
  • Java 17

1.X version

  • Spring Boot 2
  • Java 16

🧐 What's the purpose?

This starter is useful when you want to avoid calling external services, databases etc. There are a few possible use-cases, e.g.

  • when you cannot run all services your application depends on in the local environment, and you want to run your application without calling these services,
  • when you want to avoid calling services that are billed per call,
  • when your development environment is not stable and impacts the development of the service that you own,
  • when data quality is poor or hard to replicate,
  • when you are performing PoC,
  • when the service you want to use is not ready yet, it is easy to mock the response of such service,
  • and more!

💡Why not just use cache?

For the cache to work you first need to make a call. If the returned data depends on the input parameters, that becomes a problem, because you need to make many calls to capture data. Also, the cache's main purpose is to avoid expensive calls, once data is cached it doesn't change.

With this starter, you can prepare data on your own. You can run your application in LEARNING mode to speed this process up, but nothing stops you from creating the response file from scratch. It is very easy to provide many responses based on the input parameters, which makes this tool great for testing and development!

⚠️Limitations

Maps with complex keys are not supported.

⛔ Production use

This is not meant for production! The problems this starter helps to solve are mainly related to lower environments or PoC-type projects. If you cannot depend on some service in production then you should look for a different solution.

It should not be a replacement for caching solution.

👨‍⚖️ License

MIT

Feel free to use any part from this repository.