Spring引导中的Grails'BootStrap#init等价物?

时间:2015-12-21 12:26:05

标签: java spring-mvc grails web-applications spring-boot

我想在Spring Boot JPA MVC Web应用程序中填充一些初始/样本记录。在Grails中,我看到了一个示例,其中grails-app/init/BootStrap文件在init封闭中进行了初始化。

如何在Spring Boot Web应用程序中执行相同操作?

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码:

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

@Component
public class Bootstrap implements InitializingBean {

    @Override
    public void afterPropertiesSet() throws Exception {
        // YOUR CODE...
    }
}