PDF Processor reads tests from PDF, gets QR code for that text, and write it to another PDF. It also writes the extracted text in a JSON file.
Go to the terminal (command Prompt cmd
in Microsoft Windows). Open MySQL client with a user that can create new users.
For example: On a Linux, use the command
$ sudo mysql --password
Note
|
This connects to MySQL as a root, this is not the recommended way for a production server. |
Create a new database
mysql> create database localdb; -- Create the new database
mysql> create user 'user'@'localhost' identified by 'password'; -- Creates the user
mysql> grant all on localdb.* to 'user'@'localhost'; -- Gives all the privileges to the new user on the newly created database
Spring Boot gives you defaults on all things, the default in database is H2
, so when you want to change this and use any other database you must define the connection attributes in the application.properties
file.
In the sources folder, you create a resource file src/main/resources/application.properties
include::src/main/resources/application.properties
Here, spring.jpa.hibernate.ddl-auto
can be none
, update
, create
, create-drop
, refer to the Hibernate documentation for details.
-
none
This is the default forMySQL
, no change to the database structure. -
update
Hibernate changes the database according to the given Entity structures. -
create
Creates the database every time, but don’t drop it when close. -
create-drop
Creates the database then drops it when theSessionFactory
closes.
We here begin with create
because we don’t have the database structure yet. After the first run, we could switch it to update
or none
according to program requirements. Use update
when you want to make some change to the database structure.
The default for H2
and other embedded databases is create-drop
, but for others like MySQL
is none
It is good security practice that after your database is in production state, you make this none
and revoke all privileges from the MySQL user connected to the Spring application, then give him only SELECT, UPDATE, INSERT, DELETE.
This is coming in details in the end of this guide.
src/main/java/xyz/fullstack/development/job/PdfProcessorJob.java
include::src/main/java/xyz/fullstack/development/job/PdfProcessorJob.java
Note
|
This class contains the Job configuration for Batch jobs (Reader, Processor, Writer) |
Although it is possible to package this service as a traditional WAR file for deployment to an external application server, the simpler approach demonstrated below creates a standalone application. You package everything in a single, executable JAR file, driven by a good old Java main()
method. Along the way, you use Spring’s support for embedding the Tomcat servlet container as the HTTP runtime, instead of deploying to an external instance.
src/main/java/xyz/fullstack/development/Application.java
include::src/main/java/xyz/fullstack/development/Application.java
Logging output is displayed. The service should be up and running within a few seconds.