@Value注解读取配置,给静态变量赋值
摘要:springboot工程中,读取配置文件给普通变量赋值时,直接在变量声明之上添加@Value(); @Value("${server.port}") private String serverPort; 当给静态变量如上赋值时,会发现对应变量为null,该改为如下方法: @Component pub
阅读全文
posted @
2021-08-30 23:02
西八没天台
阅读(347)
推荐(0)
SpringBoot中非Controller类调用service方法出现null空指针
摘要:原因:service无法导入到非controller层中去。 解决方法:注入bean @Component //重点 public class TestServerse{ @Autowired //正常引用目标service private OtherService otherService ; /
阅读全文
posted @
2021-08-19 22:18
西八没天台
阅读(1602)
推荐(0)