功能
在spring-boot项目启动时,将会打印项目的基本信息:服务名称,pom中的项目版本,以及jar包构建的时间,方便检测服务是否更新到正确的版本,也可以提供接口访问
实现步骤(steps 2)
step 1 添加服务启动的前置执行代码
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import javax.annotation.PostConstruct;
/**
* 初始化bean之前执行即服务启动的前置代码
*/
@Configuration
@Slf4j
public class BeanPostConfig implements BeanPostProcessor {
@Value("${project.version}")
private String serviceVersion;
@Value("${project.builddate}")
private String serviceBuildDate;
@Value("${spring.application.na