Social Media

Auto-Generating Spring Security: Accessing the In-memory Database

I came across a blog post on Spring Framework guru’s  which uses the h2 database console, and thought it would be useful to combine the console with my own spring security tutorials –

I’ve updated the parkrunpb project on github to replace hsqldb with h2database. Ive also introduced a new class, which registers the h2 database servlet

Start the application –

mvn spring-boot:run

Access The Console

You can access the console through -http://localhost:8080/console


You then make sure the JDBC URL is –


And login –


The layout shows the tables we loaded in schema.sql on the right (CUSTOM_AUTHORITIES, CUSTOM_USERS and PARKRUNCOURSE)

Combine it with spring security

The next step is to combine with Spring Security, so I’ll use the configuration from the previous tutorial –Auto-generating Spring Security Tutorial – Custom JDBC Realms

We start with our class –

We then add to the configure method –

The method then becomes –

This means the normal security from the original tutorial is applied to the application, but we have a special rule for the console

You can then test the application as before with the username/password customadmin/customadmin. You could also insert or update courses,

About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: