首页 > 编程知识 正文

webpack配置文件,动态指定maven配置

时间:2023-05-05 09:23:19 阅读:145228 作者:4842

前言:自定义配置文件是我们日常开发中常用的资源,而spring仅提供这种中匹配方式,不支持我们自定义的配置文件名称。 例如,customize-dev.properties,但是spring提供了一个注释,可以方便地加载我们的自定义配置文件。 那是@ ()

自定义配置文件customize-dev.properties

customize.name=dev是@PropertySource加载配置文件import lombok.Data; importorg.spring framework.boot.context.properties.configuration properties; importorg.spring framework.context.annotation.property source; importorg.spring framework.stereotype.com ponent; @ data @ component @ property source (value=' class path :定制$ { customize.profiles.active 3360 }.properties @ ignoreInvalidFields=true )公共类定制{专用名; }配置文件- d customize.profiles.active=-dev启动测试import com.learning.Shiro.config.customize; import lombok.extern.slf4j.slf4j; importorg.spring帧work.http.http status; importorg.spring帧. http.response entity; importorg.spring framework.web.bind.annotation.request mapping; importorg.spring帧web.bind.annotation.rest controller; import javax.annotation.resource; @ rest controller @ sl F4 jpublicclasscustomizecontroller { @ resourceprivatecustomizecustomize; @请求映射(value='/' )公共响应实体? index () returnnewresponseentitycustomize (customize,HttpStatus.OK ); }如果扩展结果{name: 'dev'}或更高版本,则只能加载一个配置文件,而且很优雅。 虽然可以通过实现PropertySourceFactory来自定义和加载配置文件,但这种方式是他本人从未尝试过的。 尝试过的朋友可以试着共享自己的实现方案。

import java.io.IOException; importorg.spring framework.core.env.property source; importorg.spring framework.lang.nullable; publicclassdefaultpropertysourcefactoryimplementspropertysourcefactory { publicdefaultpropertysourcefactory } { } publicproprperperacer createpropertysource (@ nullablestringname,编码资源资源) throws IOException { return name!=null? newresourcepropertysource (名称,资源) :newresourcepropertysource (资源)资源; }} DefaultPropertySourceFactory是官方提供的默认配置文件加载方式,您可以根据业务定制实现自己的加载方式。

以上是本作品所有文章的总结,主要介绍了@PropertySoure注释的基本使用。 如果有更好的方案,欢迎讨论分析。 谢谢你。

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