<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-configuration-processorartifactId>
<optional>trueoptional>
dependency>
application.yml
lhz:
project:
title: 李昊哲-小课
slogan: 桃李不言下自成蹊
map: {"B":"https://space.bilibili.com/480308139","C":"https://blog.csdn.net/qq_24330181"}
list:
- https://space.bilibili.com/480308139
- https://blog.csdn.net/qq_24330181
lhzSite:
name: 李昊哲-小课
url: https://space.bilibili.com/480308139
siteList:
- name: 李昊哲-小课 B站
url: https://space.bilibili.com/480308139
- name: 李昊哲-小课 C站
url: https://blog.csdn.net/qq_24330181
package com.lihaozhe.constant;
import lombok.*;
/**
* @author 李昊哲
* @version 1.0.0 2022/7/27 上午9:57
*/
@Setter
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class LhzSite {
private String name;
private String url;
}
package com.lihaozhe.constant;
import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.List;
import java.util.Map;
/**
* @author 李昊哲
* @version 1.0.0 2022/7/28 下午1:36
*/
@Setter
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "lhz.project")
public class ProjectConstant {
private String title;
private String slogan;
private Map<String, String> map;
private List<String> list;
private LhzSite lhzSite;
private List<LhzSite> siteList;
}
package com.lihaozhe.constant;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author 李昊哲
* @version 1.0.0 2022/7/28 下午1:39
*/
@Slf4j
@SpringBootTest
public class ProjectConstantTest {
@Autowired
private ProjectConstant constant;
@Test
public void test() {
log.info("常量 >>> {}", constant);
log.info("title >>> {}", constant.getTitle());
log.info("slogan >>> {}", constant.getSlogan());
constant.getMap().forEach((k, v) -> log.info("key >>> {},\tvalue >>> {}", k, v));
constant.getList().forEach(item -> log.info("item >>> {}", item));
log.info("网站名称 >>> {},\t网站地址 >>> {}", constant.getLhzSite().getName(), constant.getLhzSite().getUrl());
constant.getSiteList().forEach(lhzSite -> log.info("网站名称 >>> {},\t网站地址 >>> {}", lhzSite.getName(), lhzSite.getUrl()));
}
}
jwt.properties
package com.lihaozhe.constant;
import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* @author 李昊哲
* @version 1.0.0 2022/7/28 下午2:16
*/
@Setter
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "jwt")
@PropertySource("classpath:jwt.properties")
public class JwtConstant {
private String key;
private long accessExpiryDate;
private long codeExpiryDate;
}
package com.lihaozhe.constant;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author 李昊哲
* @version 1.0.0 2022/7/28 下午2:19
*/
@Slf4j
@SpringBootTest
public class JwtConstantTest {
@Autowired
private JwtConstant jwtConstant;
@Test
public void test() {
log.info("秘钥 >>> {}", jwtConstant.getKey());
log.info("accessExpiryDate >>> {}", jwtConstant.getAccessExpiryDate());
log.info("codeExpiryDate >>> {}", jwtConstant.getCodeExpiryDate());
}
}