Preload data in spring boot?


I am starting with a project and I want to start inserting the application insert some tables, I would do it in the BD but I have attributes "created_At" and "update_At" :

package com.example.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;



public abstract class AuditModel {
private Date createdAt;

private Date updateAt;

public Date getCreatedAt() {
    return createdAt;

public void setCreatedAt(Date createdAt) {
    this.createdAt = createdAt;

public Date getUpdateAt() {
    return updateAt;

public void setUpdateAt(Date updateAt) {
    this.updateAt = updateAt;


which I inherit from all my entities. spring boot handles the insertions to these attributes, some way to perform the pre-insertion?

asked by liryco 25.11.2018 в 17:51

1 answer


You can try implementing the ApplicationRunner interface, everything you put in the run method will be executed when you initialize the spring context. link

public class OnBoot implements ApplicationRunner{

    public void run(ApplicationArguments args) throws Exception {
        //tu lógica
answered by 23.01.2019 в 23:13