所有的配置都是写在appliaction.properties或application.yml文件里,那么如果不想写在这里面怎么处理呢使用@PropertySource可以解决
所在的配置都是优先注入appliaction.properties或application.yml里面的数据
如果要不一样,必须修改配置文件引入的前缀
自定义配置文件的名称,需要使用此注解 来引入配置文件
//使用student前缀去IOC容器里面读取配置文件
@PropertySource("classpath:student.properties")
使用spring的配置方法
自定义xml 配置文件,用此注解 位置:一般放在启动类上
//启动类
@SpringBootApplication
// 引入自定义配置文件
@ImportResource(value = {"classpath:applicationContext.xml"})
public class SpringbootHelloApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootHelloApplication.class, args);
}
}