Skip to content

Instantly share code, notes, and snippets.

@kazz12211
Created August 28, 2017 01:26
Show Gist options
  • Save kazz12211/2b9717a56f1a28623af30f8592727dc9 to your computer and use it in GitHub Desktop.
Save kazz12211/2b9717a56f1a28623af30f8592727dc9 to your computer and use it in GitHub Desktop.
Spring Bootでアプリケーション起動時に何らかの処理を実行するコード例
package mypackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class MyApplication {
private static Logger log = LoggerFactory.getLogger(MyApplication.class);
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(MyApplication.class, args);
MyApplication app = ctx.getBean(MyApplication.class);
app.execStartup(args);
}
public void execStartup(String[] args) {
// ここにアプリケーション起動時に実行したい処理を書く
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment