Home > Java > javaTutorial > body text

How does Springboot execute code before startup?

PHPz
Release: 2023-05-20 20:49:04
forward
2292 people have browsed it

Before Springboot automatically instantiates a class, we need to prepare some data to be used when the type is instantiated. After testing, adding the annotation @PostConstruct to the startup class is effective.

@SpringBootApplication
public class MyApplication {
	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);
	}
	// springboot正式启动前
	@PostConstruct
	public void postConstruct(){
		System.out.println("执行Springboot正式启动前的代码")
	}
}
Copy after login

The methods of implementing Spring's ApplicationRunner and CommandLineRunner interfaces are only executed after Springboot is started.

The above is the detailed content of How does Springboot execute code before startup?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template