首页 > 编程知识 正文

springboot版本(springboot的优点)

时间:2023-05-04 08:25:36 阅读:87463 作者:316

1.修改pom.xml,过滤src/main/resources目录下.properties文件

日本航空公司

pom.xml代码:

大楼

finalnamexxxx /最终名称

插件

插件

groupid org.spring框架. boot/groupid

artifactidspring-boot-maven -插件/工件id

/plugin

/plugins

资源

资源

目录src /主/资源/目录

excludes

排除* * */* .属性/排除

/excludes

/资源

/资源

/build

2.在resources目录下创建META_INF/spring.factories文件(注意META_INF文件夹也是要创建的)

spring.factories

spring.factories的内容:

org.spring框架. boot.env .环境物理处理器=com.config .本地化服务处理器

3.新建LocalSettingsEnvironmentPostProcessor.java加载外部属性文件application.properties

localsettingsenvironmentpostprocessor

localsettingsenvironmentpostprocessor.Java代码如下:

软件包com.config;

importorg.spring框架. boot.spring应用程序;

importorg.spring框架. boot.env .环境物理处理器;

importorg.spring框架.核心.环境.配置环境;

importorg.spring框架.核心. env.mutablepropertysources;

importorg.spring框架.核心. env .属性属性资源;

importorg.spring框架.核心. io .文件系统资源;

importorg.spring框架.核心. io.support .属性加载工具;

导入日本文件;

导入Java.IO执行;

导入Java.util .属性;

//*

* @author光州程序猿

* * @版本1.0

*/

publicclasslocalsettingsenvironmentpostprocessorimplementsenvironmentpostprocessor {

私有状态金融定位=' c :\用户 桌面 应用程序.属性';

@Override

publicvoidpostprocessenvironment (配置环境可配置环境,springapplicationspringapplication ) {

文件文件=新文件(位置;

特里

mutablepropertysourcespropertysources=可配置环境. getproperty sources (;

属性属性=加载属性(文件;

属性源.添加第一个(newpropertiespropertysource )、属性);

缓存(执行) {

e .打印堆栈跟踪(;

}

}

privatepropertiesloadproperties {

filesystemresourceresource=newfilesystemresource (f;

特里

returnpropertiesloaderutils.load属性(资源;

}catch(ioexceptionex ) {

thrownewillegalstateexception (' failedtoloadlocalsettingsfrom ' f.getabsolutepath ',ex );

}

}

}

启动SpringBoot项目,指定外部application.properties启动成功。

启动结果

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。