mthaler / spring-task-scheduling

Spring task scheduling example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-task-scheduling

Spring task scheduling example from the Pro Spring 5 book ported to Kotlin and Postgres.

Install PostgreSQL

On Debian Linux, PostgreSQL can be installed with the following command:

# apt-get install postgresql postgresql-doc

Both the default database user and default database are called postgres

Create a user and database for the system user

By default, Postgres uses a concept called “roles” to handle authentication and authorization. After installation Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.

Use su to switch to the postgres acount and create a user with the same name as the system user:

$ su -
# su -s /bin/bash postgres
postgres@debian:/root$ createuser -s username

The -s option grants superuser privileges.

Next we need to create a database for the user:

postgres@debian:/root$ createdb -O username username

Now try to start psql as a normal user:

$ psql
username=# \q

Create cars user and database

After setting up a user for the local system user, we no longer need to switch to the postgres account to run postgres commands. Add an instagram postgres user:

$ createuser -P cars

This creates an cars user that is not allowed to create new databases or roles and is not superuser. The -P flag will display a password prompt to set a password for the user.

To create the cars database, run the follwing command:

$ createdb -O cars cars

Create tables

The Spring Hibernate example will automatically create tables before running the test and drop them after running the tests. It will also add test data to the tables.

Runnig tests

Before running tests, set the correct password in src/main/resources/db/jdbc.properties. SingerDaoTest will test CRUD operations.

About

Spring task scheduling example


Languages

Language:Kotlin 100.0%