SpringBoot中静态类使用配置文件经常遇到读取为NULL的情况,现在我就告诉大家。

简介: SpringBoot中静态类使用配置文件经常遇到读取为NULL的情况,现在我就告诉大家。

----------------------------------application-jwt.properties------------------------

c.jwt.toke.secret=xxx
c.jwt.toke.issuer=xxx
c.jwt.toke.userno=xx
c.jwt.toke.date=ss

----------------------------------JwtProConfig,java---------------------------------

 
import javax.annotation.PostConstruct;
 
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
 
@Configuration
@PropertySource({"classpath:application-jwt.properties"})
@ConfigurationProperties(prefix = "c.jwt.toke")
public class JwtProConfig {
public static String TOKEN_SECRET;
public static String ISSUER;
public static String USERNO;
public static Long DATE;// = 1L; //10秒钟
public String  secret;
public String  issuer;
public String  userno;
public Long  date;
 
//这个一定要加
@PostConstruct
public void JwtProConfigValue() {
    TOKEN_SECRET = this.secret;
    ISSUER = this.issuer;
    USERNO = this.userno;
    //DATE = Long.valueOf(this.date);
    DATE = this.date;
}
 
 
public String getSecret() {
    return secret;
}
 
 
public void setSecret(String secret) {
    this.secret = secret;
}
 
 
public String getIssuer() {
    return issuer;
}
 
 
public void setIssuer(String issuer) {
    this.issuer = issuer;
}
 
 
public String getUserno() {
    return userno;
}
 
 
public void setUserno(String userno) {
    this.userno = userno;
}
 
 
public Long getDate() {
    return date;
}
 
 
public void setDate(Long date) {
    this.date = date;
}
 
}

----------------------------------最后直 接类.静态属性 -------------------------------

相关文章
|
JSON Java fastjson
微服务——SpringBoot使用归纳——Spring Boot返回Json数据及数据封装——使用 fastJson 处理 null
本文介绍如何使用 fastJson 处理 null 值。与 Jackson 不同,fastJson 需要通过继承 `WebMvcConfigurationSupport` 类并覆盖 `configureMessageConverters` 方法来配置 null 值的处理方式。例如,可将 String 类型的 null 转为 "",Number 类型的 null 转为 0,避免循环引用等。代码示例展示了具体实现步骤,包括引入相关依赖、设置序列化特性及解决中文乱码问题。
943 0
|
Java Spring
解决Springboot集成ElasticSearch 报错:A bean with that name has already been defined in null and overriding
解决Springboot集成ElasticSearch 报错:A bean with that name has already been defined in null and overriding
676 2
|
Java 测试技术 Maven
Spring Boot单元测试报错java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]
Spring Boot单元测试报错java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]
836 0
|
Java
SpringBoot中静态类使用配置文件
SpringBoot中静态类使用配置文件
177 0
|
JSON 前端开发 Java
【SpringBoot实战专题】「开发实战系列」全方位攻克你的技术盲区之Spring定义Jackson转换Null的方法和实现案例
【SpringBoot实战专题】「开发实战系列」全方位攻克你的技术盲区之Spring定义Jackson转换Null的方法和实现案例
635 0
|
Java 数据库连接 API
SpringBoot【问题 01】借助@PostConstruct解决使用@Component注解的类用@Resource注入Mapper接口为null的问题(原因解析+解决方法)
SpringBoot【问题 01】借助@PostConstruct解决使用@Component注解的类用@Resource注入Mapper接口为null的问题(原因解析+解决方法)
1803 0
|
Java 数据库 Spring
spring boot 查询到的数据返回null
spring boot 查询到的数据返回null
912 0
|
JSON Java 数据格式
SpringBoot 返回参数为null,不返回的处理
SpringBoot 整合 fastjson Springboot处理返回的参数为null、或者不返回 一、通过继承WebMvcConfigurerAdapter,重写configureMessageConverters方法实现 @Configuration public class fast.
3994 0
|
JavaScript Java 关系型数据库
基于springboot的项目管理系统
本文探讨项目管理系统在现代企业中的应用与实现,分析其研究背景、意义及现状,阐述基于SSM、Java、MySQL和Vue等技术构建系统的关键方法,展现其在提升管理效率、协同水平与风险管控方面的价值。

热门文章

最新文章