Build A Spring Role Based Access Control (RBAC)

(A) Thymeleaf Template Reload

By default, Thymeleaf caches the templates, so in order to update Thymeleaf templates we need to change this behaviour. To do this, add src/main/resources/application.properties with the following property :

spring.thymeleaf.cache=false

Restart the server and you can reload Thymeleaf templates without restarting the server.

(B) Spring Hot Reload Java Class

If you wanna hot reload your java classes while developing your application, you can use spring-loaded.

The setting is easy,

Step 1 : Download springloaded.jar

Go spring-loaded to download the latest springloaded-VERSION.jar , then put it some where in your computer, for my case, it is C:\Users\moon\springloaded-1.2.4.RELEASE.jar.

Step 2 : Setting VM Arguments

Run Configurations

Add the following line in the VM arguments box,

-javaagent:C:\Users\moon\springloaded-1.2.4.RELEASE.jar -noverify

Done !

Ref :

  1. Hot Swapping in Spring Boot with Eclipse STS

(C) Loading Data Using Spring Data on Startup

Hibernate has a feature to load data on startup. Simply place a file called import.sql on your classpath, and Hibernate will execute the SQL statements in file.But , unfortunately, my import.sql (for mysql) failed in H2,

src/main/resources/import.sql

insert into role(name) values('ROLE_AGENT');            //ok
insert into role(name) values('ROLE_USER');             //ok

insert into permission(name) values('PERM_1');          //ok
insert into permission(name) values('PERM_2');          //ok
insert into permission(name) values('PERM_3');          //ok

// failed here - this is because of the this SQL query are specify for MYSQL 
insert into user(enabled,password,username,universal_key) value(1,'f5673793a9f0b7f596332fb4e7a9ae51e82edf0c94c4d88d195ba97fb130e6f544228cfe257ec90d','1','83230');
.....

errors from the console of eclipse,

2015-08-27 11:08:35.167 ERROR 4888 --- [main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000388: Unsuccessful: 
insert into user(enabled,password,username,universal_key) value(1,'f5673793a9f0b7f596332fb4e7a9ae51e82edf0c94c4d88d195ba97fb130e6f544228cfe257ec90d','1','83230')
.....

So, better don't write your own sql script to load data, ask ORM to do the favour.

Ref:

  1. Spring Security Role-based Authorization and Permissions
  2. Database Persistence with Spring Boot
  3. CharacterEncodingFilter
  4. spring boot MVC wrong encoded POST request