I am trying to extend this example: https://github.com/scratches/jpa-method-security-sample by adding a method in the controller to "signup" where a new user is dynamically added to the repo. The default set of existing users is added in the import.sql script. However, I see that my dynamically added user gets wiped out on server restart. Could you point me out the way to make sure the table gets updated persistently.
Here is my code for the signup method:
@RequestMapping(value = "signup",method = RequestMethod.GET)
public String signup(Map<String, Object> model) {
model.put("message","Sign up!");
model.put("title", "Hello Signup");
model.put("date", new Date());
users.createUser();
return "signup";
}
public void createUser() {
User u = new User();
u.setName("xxx");
u.setPassword("spring");
repo.save(u);
}
I have also made changes to loadUserByUserName
to return the correct authorities for the new user. This works fine for one server session and I can log in with the new user. However, on server restart, the user needs to be re-added. I want to prevent this.
I have a feeling that I need to do something more elaborate like configuring a persistent datasource. If that is the case, could you please point me to some resource that uses java config to do this. I am just starting on spring and this may be a basic question and of everything that I read, I am not sure what to follow.