4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring Bootでアプリケーション起動時の処理

Posted at

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) {
    		// ここにアプリケーション起動時に実行したい処理を書く
  	}
}
4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?