springboot 获取maven打包时间

springboot 获取maven打包时间

pom

java 复制代码
<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.13.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>

		<!--指定时间格式 -->
		<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
		<!--maven.build.timestamp保存了maven编译时间戳 -->
		<timestamp>${maven.build.timestamp}</timestamp>

	</properties>


	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!--lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
	</dependencies>


	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>

		<resources>
			<resource>
				<directory>src/main/resources/</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
	</build>

方式一

maven.properties

java 复制代码
# maven打包时间
maven.package_time=@timestamp@

MavenProperties

java 复制代码
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import lombok.Data;

@Configuration
@ConfigurationProperties(prefix = "maven", ignoreUnknownFields = false)
@PropertySource(value= "classpath:config/maven.properties",encoding = "utf-8")
@Data
@Component
public class MavenProperties {
    /**maven打包时间*/
    private String package_time;
}

测试

java 复制代码
	@Resource
    private MavenProperties mavenProperties;
	
	@GetMapping("/mavenTime")
	public String ah() {
		return "最新打包时间:"+modifyTime(packageTime);
	}
	
	/**
     * 修改时间为东8区
     */
    public String modifyTime(String date) {
        Date oldDate=null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            oldDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(oldDate);
        calendar.add(Calendar.HOUR_OF_DAY, +8);
        return simpleDateFormat.format(calendar.getTime());
    }	

方式二

application.yml

java 复制代码
maven:
  package_time: '@timestamp@' # maven打包时间

测试

java 复制代码
@Value("${maven.package_time}")
	private String packageTime;
	
	@GetMapping("/mavenTime")
	public String ah() {
		return "最新打包时间:"+modifyTime(packageTime);
	}
	
	/**
     * 修改时间为东8区
     */
    public String modifyTime(String date) {
        Date oldDate=null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            oldDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(oldDate);
        calendar.add(Calendar.HOUR_OF_DAY, +8);
        return simpleDateFormat.format(calendar.getTime());
    }
相关推荐
Y编程小白35 分钟前
SpringBoot的pom.xml文件中,scope标签有几种配置?
xml·spring boot·后端
m0_7482513537 分钟前
【SpringBoot】日志文件
java·spring boot·spring
m0_7482347138 分钟前
Java-33 深入浅出 Spring - FactoryBean 和 BeanFactory BeanPostProcessor
java·开发语言·spring
知初~1 小时前
java相关学习文档或网站整理
java·开发语言·学习
码农小灰1 小时前
什么是缓存穿透、缓存击穿、缓存雪崩,在项目中是如何解决和预防?它们分别会带来什么危害?
java·缓存
a栋栋栋1 小时前
apifox
java·前端·javascript
A22742 小时前
Redis——数据淘汰策略
java·redis·缓存
玄天灵2 小时前
问题-01
java·mybatis
健康平安的活着2 小时前
springboot整合log4j2日志框架1
spring boot·后端·log4j
是一只派大鑫2 小时前
从头开始学MyBatis—04缓存、逆向工程、分页插件
java·后端·mybatis