- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我通过指定 WarLauncher(spring boot loader 的一部分)作为我的启动类创建了一个可执行的 war 文件。当所有配置文件(属性、spring 上下文等)都是我的资源文件夹的一部分时,它工作正常。我希望我的 war 的消费者需要控制属性文件。因此需要在 war 文件之外加载它。我期待配置文件夹中的属性文件(与 war 文件并排部署)。我试图通过使用 Maven 插件向 list 中添加适当的类路径条目,但没有成功。
以下是我的 maven POM 文件的相关部分的样子:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
</manifest>
<manifestEntries>
<Start-Class><<myclass_dont_worry_about_this>></Start-Class>
<Class-Path>config/</Class-Path>
</manifestEntries>
</archive>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
我正在使用 Spring ClassPathResource() 加载属性文件。下面显示了相同的代码片段:
InputStream stream = new ClassPathResource(classPathConfigFilePath).getInputStream();
Proerties properties = new Properties();
properties.load(stream);
在运行时,它无法定位导致 FileNotFoundException 的属性文件。
谢谢。
最佳答案
默认情况下,Spring-Boot 在以下位置搜索 application.properties
文件
/config
包/config
当前目录的子目录所有这些文件(如果可用)都按该顺序加载,这意味着 1 的属性可以被 2、3、4 覆盖。所有加载的属性都可以作为 Environment
的一部分使用,因此可以在占位符中用于配置。
作为对上述加载规则的补充还有profile可以加载特定文件。对于给定的配置文件,它还将尝试加载 application-{profile}.properties
。对于该特定文件,还会考虑上述加载规则。
所有加载的属性都可以通过 Environment
使用,这意味着可以通过 spring unified property management 使用.可以直接使用 Environment
来检索配置参数,也可以使用占位符和 @Value
注释进行配置
@Configuration
public class SomeConfigClass {
@Autowired
private Environment env;
public DataSource dataSource() {
SimpleDriverDataSource ds = new SimpleDriverDataSource();
ds.setUsername(env.getProperty("jdbc.username"));
ds.setPassword(env.getProperty("jdbc.password"));
ds.setDriverClass(Driver.class);
ds.setUrl(env.getProperty("jdbc.url"));
return ds;
}
}
或者用@Value
@Configuration
public class SomeConfigClass {
@Value("${jdbc.username}")
private String username;
@Value("${jdbc.password}")
private String password;
@Value("${jdbc.url}")
private String url
public DataSource dataSource() {
SimpleDriverDataSource ds = new SimpleDriverDataSource();
ds.setUsername(username);
ds.setPassword(password);
ds.setDriverClass(Driver.class);
ds.setUrl(url);
return ds;
}
}
链接
关于java - 使用spring boot loader WarLauncher时如何加载war文件之外的属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20418201/
我想要显示正在加载的 .gif,直到所有内容都已加载,包括嵌入的 iframe。但是,目前加载 gif 会在除 iframe 之外的所有内容都已加载后消失。我怎样才能让它等到 iframe 也加载完毕
首先,这是我第一次接触 Angular。 我想要实现的是,我有一个通知列表,我必须以某种方式限制 limitTo,因此元素被限制为三个,在我单击按钮后,其余的应该加载。 我不明白该怎么做: 设置“ V
我正在尝试在我的设备上运行这个非常简单的应用程序(使用 map API V2),并且出于某种原因尝试使用 MapView 时: 使用 java 文件: public class MainMap e
我正在使用 Python 2.6、Excel 2007 Professional 和最新版本的 PyXLL。在 PyXLL 中加载具有 import scipy 抛出异常,模块未加载。有没有人能够在
我想做这个: 创建并打包原始游戏。然后我想根据原始游戏中的蓝图创建具有新网格/声音/动画和蓝图的其他 PAK 文件。原始游戏不应该知道有关其他网格/动画/等的任何信息。因此,我需要在原始游戏中使用 A
**摘要:**在java项目中经常会使用到配置文件,这里就介绍几种加载配置文件的方法。 本文分享自华为云社区《【Java】读取/加载 properties配置文件的几种方法》,作者:Copy工程师。
在 Groovy 脚本中是否可以执行条件导入语句? if (test){ import this.package.class } else { import that.package.
我正在使用 NVidia 视觉分析器(来自 CUDA 5.0 beta 版本的基于 eclipse 的版本)和 Fermi 板,我不了解其中两个性能指标: 全局加载/存储效率表示实际内存事务数与请求事
有没有办法在通过 routeProvider 加载特定 View 时清除 Angular JS 存储的历史记录? ? 我正在使用 Angular 创建一个公共(public)安装,并且历史会积累很多,
使用 Xcode 4.2,在我的应用程序中, View 加载由 segue 事件触发。 在 View Controller 中首先调用什么方法? -(void) viewWillAppear:(BOO
我在某些Django模型中使用JSONField,并希望将此数据从Oracle迁移到Postgres。 到目前为止,当使用Django的dumpdata和loaddata命令时,我仍然没有运气来保持J
创建 Nib 时,我需要创建两种类型:WindowNib 或 ViewNib。我看到的区别是,窗口 Nib 有一个窗口和一个 View 。 如何将 View Nib 加载到另一个窗口中?我是否必须创建
我想将多个env.variables转换为静态结构。 我可以手动进行: Env { is_development: env::var("IS_DEVELOPMENT")
正如我从一个测试用例中看到的:https://godbolt.org/z/K477q1 生成的程序集加载/存储原子松弛与普通变量相同:ldr 和 str 那么,宽松的原子变量和普通变量之间有什么区别吗
我有一个重定向到外部网站的按钮/链接,但是外部网站需要一些时间来加载。所以我想添加一个加载屏幕,以便外部页面在显示之前完全加载。我无法控制外部网站,并且外部网站具有同源策略,因此我无法在 iFrame
我正在尝试为我的应用程序开发一个Dockerfile,该文件在初始化后加载大量环境变量。不知何故,当我稍后执行以下命令时,这些变量是不可用的: docker exec -it container_na
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我刚刚遇到一个问题,我有一个带有一些不同选项的选择标签。 现在我想检查用户选择了哪些选项。 然后我想将一个新的 html 文件加载到该网站(取决于用户选中的选项)宽度 javascript,我该怎么做
我知道两种保存/加载应用程序设置的方法: 使用PersistentStore 使用文件系统(存储,因为 SDCard 是可选的) 我想知道您使用应用程序设置的做法是什么? 使用 PersistentS
我开始使用 Vulkan 时偶然发现了我的第一个问题。尝试创建调试报告回调时(验证层和调试扩展在我的英特尔 hd vulkan 驱动程序上可用,至少它是这么说的),它没有告诉我 vkCreateDeb
我是一名优秀的程序员,十分优秀!