1.Springboot引入多个yml方法
SpringBoot默认加载的是application.yml文件,所以想要引入其他配置的yml文件,就要在application.yml中激活该文件。
定义一个application-xlsx.yml文件(注意:必须以application-开头)
application.yml中:
spring:
profiles:
active: xlsx
以上操作,xml自定义文件加载完成,接下来进行注入。
application-xlsx.yml配置文件代码:
xlsx:
build:
t: 1
g: 2
实体类:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "xlsx")
public class XlsxConfig {
private Map<String ,String > build = new HashMap<>();
}
测试:
@SpringBootTest
class ConfigurationgeneratorApplicationTests {
@Autowired
private XlsxConfig xlsxConfig;
@Test
void contextLoads() {
System.out.println(xlsxConfig);
}
}
注*自己定义的test测试类,无法Autowired,这是个问题,以后解决。