标签: properties-file

Java 属性文件。setProperty() 方法的问题

我尝试Properties使用Properties#setProperty()方法覆盖文件中的现有属性值。

但是我得到了一个额外的反斜杠...

例如,我在 Properties 文件中有以下条目:

#url to server
url=http://192.22.222.222
Run Code Online (Sandbox Code Playgroud)

当我尝试http://192.22.222.222用新值覆盖值时,http://192.33.333.333我得到了后续结果: http\://192.33.333.333

即第一次反弹是不必要的。一世

问题出在哪里?

java properties properties-file

5
推荐指数
1
解决办法
2162
查看次数

PropertyPlaceholderConfigurer 与 ReloadableResourceBundleMessageSource

在 Google 上搜索如何在 Spring 3 中配置属性文件,我得到了许多不同的答案。我发现,ReloadableResourceBundleMessageSourcePropertyPlaceholderConfigurer可用于从属性文件获取的属性。有人可以解释一下这些之间的区别吗?

properties-file spring-3

5
推荐指数
1
解决办法
3005
查看次数

在Struts 2和JSP中使用带有多个参数的getText()

我正在使用JSP开发Struts2框架.我有*.properties文件:

hover_remove=Remove access to {0} at {1}`
Run Code Online (Sandbox Code Playgroud)

我在JSP中的提交标记中:

title="%{getText('hover_remove', new String[]{{appLabel}, {locationLabel}})}"
Run Code Online (Sandbox Code Playgroud)

这将在Java中工作,但我在JSP中遇到以下错误:

/WEB-INF/pages/admin/cm/view.jsp(9,287) 
JSPG0055E: Unable to create an xml attribute from name
Run Code Online (Sandbox Code Playgroud)


getText(String, List String[])在JSP中 使用的任何提示?

jsp struts2 properties-file dynamic-variables

5
推荐指数
1
解决办法
5486
查看次数

将 <property-placeholder> 属性暴露给 Spring Environment

我有一个属性文件,我使用以下property-placeholder元素通过 XML 向 Spring 注册:

<context:property-placeholder location="classpath:foo.properties" />
Run Code Online (Sandbox Code Playgroud)

我可以使用@Value注释访问属性,例如

@Value("${prefs.key}")
private String prefValue;
Run Code Online (Sandbox Code Playgroud)

但我还需要通过 Spring Environment 访问属性,例如

@Autowired
private Environment env;

public String getValue(String key) {
  return env.getProperty(key);
}
Run Code Online (Sandbox Code Playgroud)

getValue()这里总是返回null,即使对于属性文件中定义的键也是如此,因为 using<property-placeholder>似乎不会向环境公开属性。有没有办法强制以这种方式加载的属性可以通过环境访问?

java spring properties-file spring-environment

5
推荐指数
1
解决办法
2284
查看次数

Powershell解析包含冒号的属性文件

如果我有一个包含目录(包含冒号)的.properties文件:

some_dir=f:\some\dir\etc
another_dir=d:\dir\some\bin
Run Code Online (Sandbox Code Playgroud)

然后使用ConvertFrom-StringData将Key = Value对从所述属性文件转换为哈希表:

$props_file = Get-Content "F:\dir\etc\props.properties"
$props = ConvertFrom-StringData ($props_file)
$the_dir = $props.'some_dir'
Write-Host $the_dir
Run Code Online (Sandbox Code Playgroud)

Powershell抛出一个错误(不喜欢冒号):

ConvertFrom-StringData : Cannot convert 'System.Object[]' to the type 'System.String'    required by parameter 'StringData'. Specified method is not supported.
At line:3 char:32
+ $props = ConvertFrom-StringData <<<<  ($props_file)
+ CategoryInfo          : InvalidArgument: (:) [ConvertFrom-StringData],     ParameterBindingException
+ FullyQualifiedErrorId :     CannotConvertArgument,Microsoft.PowerShell.Commands.ConvertFromStringDataCommand
Run Code Online (Sandbox Code Playgroud)

你怎么绕这个?我希望能够使用它来引用目录.符号:

$props.'some_dir'
Run Code Online (Sandbox Code Playgroud)

powershell hashtable properties-file

5
推荐指数
1
解决办法
6314
查看次数

马文。嵌套属性过滤不起作用

我有两个属性文件:

#environment.properties
env = production
Run Code Online (Sandbox Code Playgroud)

第二个文件是:

#commons.properties
production.port = 123
test.port = 567
Run Code Online (Sandbox Code Playgroud)

另外,我有需要通过 environment.properties 文件和 commons.properties 文件过滤并复制的资源文件。资源文件包含:

${${env}.port}
Run Code Online (Sandbox Code Playgroud)

所以,我想用第一个文件过滤我的资源文件并得到:${production.port}

然后我想用第二个过滤器文件过滤它并得到:123

我使用 maven 3.2.5 并且根本没有过滤资源文件。我知道存在与此问题相关的问题:https : //jira.codehaus.org/browse/MRESOURCES-70但仍未解决。

所以,我的问题是 - 有没有办法解决这个问题?(实际上,我认为应该修改资源插件以使用嵌套属性过滤)。

第二个问题 - 确实存在通过重构来避免这个问题的任何方式,我的意思是任何其他架构解决方案。或者,如果你遇到同样的问题,你会怎么做?

java filtering maven properties-file

5
推荐指数
0
解决办法
556
查看次数

从 AndroidManifest.xml 访问 config.properties

我创建了一个 Android 项目,该项目作为公共存储库存储在 GitHub 上。该项目包含不应向公众公开的 API 密钥。为了防止公众看到密钥,我将它放在了 config.properties 文件中。在 AndroidManifest.xml 中,键值包含虚拟数据。为了运行该应用程序以进行测试,我目前正在将密钥粘贴到清单中,然后再启动,并在向 GitHub 提交任何更改之前将其替换为虚拟数据。

我的问题是,如何api.key从 AndroidManifest.xml访问config.properties 中的属性?理想情况下,当 gradle 文件构建项目时,api.key 值被插入到 AndroidManifest.xml 中,但从未在 GitHub 上看到,因为 .gitignore 文件不允许提交 .properties 文件。

java xml android properties-file

5
推荐指数
0
解决办法
180
查看次数

如何使用 .properties 文件中的条目创建哈希映射

我想用 .properties 文件中的条目创建一个哈希映射。我的属性文件如下所示:

##AA
key1 = A1
key2 = A2
key3 = A3
##BB
key1 = B1
key2 = B2
key3 = B3
##CC
key1 = C1
key2 = C2
key3 = C3, C4
##DD
key1 = D1
key2 = D2
key3 = D3, D4
Run Code Online (Sandbox Code Playgroud)

我将在 Excel 表中维护 AA、BB、CC、DD。

row1 = AA
row2 = BB
row3 = CC
row4 = DD
Run Code Online (Sandbox Code Playgroud)

我想遍历所有行,当它在第一行时,它应该输入

key1 = A1
key2 = A2
key3 = A3
Run Code Online (Sandbox Code Playgroud)

成一个哈希图

第二行它应该输入

key1 = B1
key2 = B2
key3 …
Run Code Online (Sandbox Code Playgroud)

java excel hashmap properties-file

5
推荐指数
1
解决办法
1万
查看次数

使用Java API生成属性文件时,为什么使用反斜杠转义冒号?

示例代码:

public final class Test
{
    public static void main(final String... args)
        throws IOException
    {
        final Properties properties = new Properties();

        properties.setProperty("foo", "bar:baz");

        // Yeah, this supposes a Unix-like system
        final Path path = Paths.get("/tmp/x.properties");

        try (
            // Requires Java 8!
            final Writer writer = Files.newBufferedWriter(path);
        ) {
            properties.store(writer, null);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我:

$ cat /tmp/x.properties 
# The date here
foo=bar\:baz
Run Code Online (Sandbox Code Playgroud)

冒号用反斜杠逃脱.事实上,所有的冒号都是.

奇怪的是,如果我手动生成属性文件并且 "冒走"冒号,那么也会读取属性.

那么,为什么编写过程Properties(无论你使用的方式Writer还是OutputStream顺便使用的方式)以这种方式逃避冒号?

java properties-file

5
推荐指数
1
解决办法
337
查看次数

如何获得EAR以从WAR读取属性文件?

我正在使用Wildfly 11和Java8。我正在尝试部署包含多个WAR文件的EAR文件。我的WAR文件之一在其web.xml中包含了此文件...

<context-param>
    <param-name>Owasp.CsrfGuard.Config</param-name>
    <param-value>csrfguard.properties</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

有问题的文件在我的WAR之一内

myapp.war/WEB-INF/classes/csrfguard.properties
Run Code Online (Sandbox Code Playgroud)

当我自己部署WAR时,一切都部署良好。但是,当我部署包含WAR的EAR时,出现一个错误,抱怨无法找到属性文件...

Caused by: java.io.IOException: unable to locate resource - csrfguard.properties
    at org.owasp.csrfguard.CsrfGuardServletContextListener.getResourceStream(CsrfGuardServletContextListener.java:85)
    at org.owasp.csrfguard.CsrfGuardServletContextListener.contextInitialized(CsrfGuardServletContextListener.java:36)
    ... 10 more
Run Code Online (Sandbox Code Playgroud)

我感觉到发生了类加载器问题,我没有弄清楚如何解决。如何告诉我的EAR文件在哪里可以找到相关的属性文件?

ear war classloader properties-file wildfly

5
推荐指数
1
解决办法
404
查看次数