application.properties文件内容
pig.id=11 pig.name=GGBond
Pig类
@Component @ConfigurationProperties(prefix = "pig")//prefix表示前缀,将前缀是pig的值绑定 public class Pig { private Integer id; private String name; public Pig() { } public Pig(Integer id, String name) { this.id = id; this.name = name; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Pig{" + "id=" + id + ", name='" + name + '\'' + '}'; } }
主程序入口
@SpringBootApplication public class Boot304Application { public static void main(String[] args) { var ioc = SpringApplication.run(Boot304Application.class, args); Pig bean = ioc.getBean(Pig.class); System.out.println("pig = " + bean); } }
使用了网上提供的所有方法,都无效,使用的springBoot版本为3.1.1,JDK为17,新建了项目并更改两个版本,jdk1.8\SpringBoot2.xx发现可以了,还以为是版本问题,之后再将springBoot版本和jdk版本为17,仍然可以,最后在原来的项目中重新新建模块成功,目测是项目结构出了问题,核心问题暂未找到。要是有人也遇到,请求指点。
- ConfigurationProperties application properties 标签 文件configurationproperties application properties application springboot properties文件 全局application properties文件 properties mybatis标签 文件 application properties文件 application springboot properties就是 jdbctemplatedemo jdbctemplate application properties application properties数据库 数据 application properties sloans application树叶springboot properties