这篇文章主要介绍在springboot中如何使用依赖jar包中的yml文件。
java web项目都是分模块的,比如这个项目web模块依赖 model模块
第一种方法:
在web模块中引用model中的yml文件
主要就是图4
spring: application: profiles: include: model
这种方法中 application-model.yml的前缀一定要和主在配置文件application.yml的名字一致
第二种方法:
就是在webapplication中添加绿色代码
@bean public static propertysourcesplaceholderconfigurer properties() { propertysourcesplaceholderconfigurer configurer = new propertysourcesplaceholderconfigurer(); yamlpropertiesfactorybean yaml = new yamlpropertiesfactorybean(); yaml.setresources(new classpathresource("application-model.yml")); configurer.setproperties(yaml.getobject()); return configurer; }
到此这篇关于springboot使用外部yml文件的两种方法的文章就介绍到这了,更多相关springboot外部yml文件内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论