Persisting data within the Spring Boot app - spring-boot

I am creating a small application using Spring Boot, this application allows users to store XML templates which can be reused in various scenarios.
The XML templates are small and will be less that 100 lines each, also there will not be more than 20 templates. I don't want to use a separate database to store this small information.
Also I don't want to store this information in memory as I want to retain the data when the app is restarted.
What is the suggested option to store this kind of data within the Spring Boot app itself without using an external database ?

Use H2 database with in memory db or save it on local disk. Or you can go for plain old write file to disk and just write a file to the disk and have another file to keep track of meta information for your writes. But this will help you only if you can ensure you have access to servers and they in turn are not volatile. Spring boot as such has not out of box solution for this other than embedded database

Related

Spring Content(1.2.5) JPA maximum file size limitation(Postgres)

Does Spring Content have some limitations regarding file size in PostgreSql? I tried to save 7,4 GB file, works well. But which type is used under the hood, how much data we can save per file
Spring Content JPA detects the database type from the connection and chooses an appropriate BLOB API to use.
In the case of PostgreSql it uses the Large Object API. As such we are constrained by their limitations

Which datastore (database) should be used for Spring-boot REST API application with AZURE

There are may blog available around this but still not getting exactly what is needed.
I am trying to write a REST API with Spring Boot and store data in database. Here the database structure may change (new tables can get introduced or some existing names may get renamed).
Which DB can be used so that there would be minimal code changes needed both at java side and DB side.
What could be a best design approach in this scenario considering technology stack as Spring Boot and Azure
Please visualize about your persistent storage? Why Azure Only? Refine question.
e.g. H2 database with Spring Boot is the most memory efficient.
see Lightest Database to be packed with an application
About Minimal code changes - I'd go with one of the ORM - JPA(or Hibernate). So will only need to maintain #Entity class on java side.
Don't forget - minimal changes still need to be addressed at database & Java side.

What is the secure and efficient way of storing files uploaded by user in Spring Project?

I have a spring project where the user will upload their files. Other users are going to pay to download that file. What is the best way to achieve this? I'm thinking of converting it to bytes and store it to database. I don't want to directly store the file in some folder in the project. Is there any other way?
You should take a look at the community/companion project Spring Content.
If you are familiar with Spring Data then this project is for unstructured data (i.e. documents, images, videos, etc) what Spring Data is for structured data.
Like Spring Data, it provides a simple, labor-saving programming interface that allows you very quickly and easily create REST APIs for uploading/downloading content, associating that content with Spring Data entities should you want to, and managing it all on the filesystem, or as BLOBs in the database, or in the cloud in something like S3.
Spring Content will provide a programming/modeling framework that should enable you to easily create a content management site with its content behind a paywall.

H2 databse to load data only once, but on app ending not to drop data

I gave a spring boot application that uses an embedded H2. What i need is on the first start of the application, to load the data form the data.sql. Every time the application ends, or breaks, the data should be maintained. The reason for this, is that i deploy my application on heroku, which for free use, sleeps after 30 minutes.
You have to use the database in embedded mode. See here.
So your datasource url have to be something like this:
spring.datasource.url=jdbc:h2:~/myDbFile;DB_CLOSE_ON_EXIT=FALSE
You can make your data.sql load conditionally and use a file H2 database see https://www.javatips.net/blog/h2-file-database-example

Purpose of Custom cache mule

Mule got inbuild object stores to cache data, But what is the purpose of using custom object stores under caching strategies? If possible, Please mention a usecase.
Custom object stores are useful when you want to use a custom persistence mechanism for your ObjectStore's
By default Mule provides two implementations, in-memory and a file based persistent store.
One possible use-case is, if you use Enterprise Edition have clustering enabled, you also have the ability to share these stores across multiple Mule nodes. However if you do not use EE or clustering but still want to share data between multiple Mule's, then you will need to use a persistent object store that can be shared across multiple mule nodes.
The ObjectStore interface has many implementations so you can choose a persistence mechanism that best suits you. Examples include Redis, Ehcache, Mongo, Cassandra, JDBC. More on this here:http://java.dzone.com/articles/synchronizing-data-across-mule
Ryan has given the correct explanation.. I just want to add:-
Mule uses object stores whenever it needs data to persist for later retrieval.
Custom Object store can be configure using Java classes and you can customize the Object store as per your need..
You can customize it and control your Cache and the Cache Keys, as well as store and retrieve the data, log you Cache keys and Cache contents, list you Cache keys etc from the Java class and that means full control on the Custom Object store ..
Please go through the following links :-
http://ricston.com/blog/cache-scope-ehcache/
http://java.dzone.com/articles/cache-scope-ehcache
http://www.mulesoft.org/documentation/display/current/Mule+Object+Stores

Resources