标签: properties-file

Spring的ReloadableResourceBundleMessageSource没有找到属性文件

我在WEB-INF/i18n目录下有两个文件:

  • application.properties
  • messages.properties

我已正确配置我的ReloadableResourceBundleMessageSource bean如下(spring mvc):

<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
        p:fallbackToSystemLocale="false"/>
Run Code Online (Sandbox Code Playgroud)

然而我从Spring mvc得到这个:

2012-09-03 02:59:45,911 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - Loading properties [application.properties]
2012-09-03 02:59:45,912 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - No properties file found for [WEB-INF/i18n/application_fr] - neither plain properties nor XML
2012-09-03 02:59:45,912 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - Loading properties [messages.properties]
2012-09-03 02:59:45,912 [http-bio-8080-exec-4] DEBUG org.springframework.context.support.ReloadableResourceBundleMessageSource - No properties file found for [WEB-INF/i18n/messages_fr] - neither plain properties nor XML
Run Code Online (Sandbox Code Playgroud)

任何人都可以建议吗?我可以将属性文件移动到类路径并相应地更改我的配置,但我宁愿了解发生了什么.

spring resourcebundle spring-mvc spring-roo properties-file

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

Bash脚本属性文件使用'.' 在变量名称中

我是bash脚本的新手,对于在bash脚本中使用.properties文件中的属性有疑问.

我见过一个使用'.'的bash属性文件.变量名之间,例如:

this.prop.one=someProperty
Run Code Online (Sandbox Code Playgroud)

我看到他们在一个脚本中调用,如:

echo ${this.prop.one}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试设置此属性时,我收到一个错误:

./test.sh: line 5: ${this.prop.one}: bad substitution
Run Code Online (Sandbox Code Playgroud)

如果我没有','我可以使用属性.在变量名中,并包含props文件:

#!/bin/bash
. test.properties
echo ${this_prop_one}
Run Code Online (Sandbox Code Playgroud)

我真的希望能够使用'.' 在变量名中,如果可能的话,不必包含.脚本中的test.properties.

这可能吗?

更新:

谢谢你的回答!那么,这很奇怪.我正在使用一个看起来像这样的bash脚本(glassfish服务):

#!/bin/bash

start() {
        sudo ${glassfish.home.dir}/bin/asadmin start-domain domain1
}

...
Run Code Online (Sandbox Code Playgroud)

...还有像这样的属性文件(build.properties):

# glassfish
glassfish.version=2.1
glassfish.home.dir=${app.install.dir}/${glassfish.target}
...
Run Code Online (Sandbox Code Playgroud)

那么,必须有一些方法来做到这一点吗?如果它们在属性文件中声明,这些可能不被视为"变量"吗?再次感谢.

linux bash scripting properties-file

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

根据输入 - java Spring在运行时从属性文件中获取值

我有我的colour.roperties文件

rose = red
lily = white
jasmine = pink
Run Code Online (Sandbox Code Playgroud)

我需要获得颜色的值

String flower = runTimeFlower;
@Value("${flower}) String colour;
Run Code Online (Sandbox Code Playgroud)

我们将在运行时得到花的价值.我怎么能在java Spring中做到这一点.我需要在运行时根据用户输入获取单个值(从属性文件中定义的50个值中).如果我不能使用@Value,你能告诉我其他方法吗?

java spring properties-file

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

在运行时通过Java中的命令提示符加载配置文件(project.properties)

我想通过java中的命令提示符加载属性文件。

属性文件名:project.properties

java -classpath .;test.jar; com.project.Main
Run Code Online (Sandbox Code Playgroud)

如果我将通过命令提示符加载属性文件,将是什么命令。

预先感谢。

我已经在命令提示符下执行了下面提到的命令,但没有得到任何输出。

java -classpath。; test.jar; -DPROP_FILE =“ C:\ Program Files \ DemoApp \ config \ project.properties” com.project.Main

java cmd properties-file

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

如何在plist中添加预定义值?

我必须创建一个配置plist.在那里我想为一个字段设置一些预定义的值,以便其他人可以从plist中的下拉列表中选择值.有点像这个屏幕,用户如何从下拉菜单中选择语言.这是来自XCode的plist

是否可以在Plist中定义一组预配置的值?

xcode objective-c properties-file ios

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

intellij,关闭ascii处理属性

不幸的是,我无法在Intellij中找到一个选项,它可以让我在属性文件(*.properties)(UTF-8)中显示ascii转义字符进行翻译,这意味着intellij会自动显示转义字符的结果,但是我需要在不使用外部观察者(vi,mate等)的情况下确认逃跑.

此外,intellij中的diff查看器实际显示对转义字符的更改也会很不错.

以下是转义字符串的示例:

key=Nak\u0142ad
Run Code Online (Sandbox Code Playgroud)

Intellij总是这样显示:

key=Nak?ad
Run Code Online (Sandbox Code Playgroud)

即使在文本编辑器模式下打开*.properties文件,字符串也会被转义...

编辑:我正在使用

IntelliJ IDEA 2016.1.2构建#IU-145.972,构建于2016年5月14日JRE:1.8.0_73-b02 x86_64 JVM:Oracle公司的Java HotSpot(TM)64位服务器VM

java ascii utf-8 intellij-idea properties-file

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

如何将GeneratedKey添加到config.properties文件?

我正在尝试加密和解密密码,并且这些生成密钥到目前为止都很好.现在我需要将此密钥存储在属性文件中,但是当我添加密钥时,它看起来像这样:

#Tue Nov 01 08:22:52 EET 2016
KEY=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000
Run Code Online (Sandbox Code Playgroud)

所以我怀疑我的代码可能有问题?!?!

并且我的代码中有一部分=

private byte[] key = new byte[16];

public void addProperties(String x, String z) {
    Properties properties = new Properties();
    String propertiesFileName = "config.properties";
    try {
        OutputStream out = new FileOutputStream(propertiesFileName);
        properties.setProperty(x, z);
        properties.store(out, null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void generateKey() {
    KeyGenerator keygen;
    SecretKey secretKey;
    byte[] keybyte = new byte[64];
    try {
        keygen = KeyGenerator.getInstance("AES");
        keygen.init(128);
        secretKey = keygen.generateKey();
        keybyte = secretKey.getEncoded();
        key = keybyte;

 //THIS …
Run Code Online (Sandbox Code Playgroud)

java properties-file key-generator

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

如何使用main方法访问Spring Boot应用程序中application.properties文件中的值

我在src/main/resources文件夹中有一个application.properties.它有一个属性

username=myname
Run Code Online (Sandbox Code Playgroud)

我上课了

public class A
{
    @Value("${username}")
    private String username;

    public void printUsername()
    {
       System.out.println(username);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在我的main方法中调用printusername函数时,如下所示

public static void main(String[] args) 
{
    A object=new A();
    object.printUsername();
}
Run Code Online (Sandbox Code Playgroud)

它打印为null.请有人告诉我我错过了什么?

java spring properties-file spring-boot

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

在spring boot中从属性文件中注入值数组

好的,所以我有config.properties...:

market.curpairs[0].name=EuroDollar
market.curpairs[0].symbol=EURUSD
market.curpairs[0].minamount=0.1
market.curpairs[1].name=EuroFranken
market.curpairs[1].symbol=EURCHF
market.curpairs[1].minamount=0.1
market.currs[0].name=Euro
market.currs[0].symbol=EUR
market.currs[0].minamount=1.0
market.currs[0].withfee=0.1
market.currs[1].name=Dollar
market.currs[1].symbol=USD
market.currs[1].minamount=1.0
market.currs[1].withfee=0.1
market.currs[2].name=Franken
market.currs[2].symbol=CHF
market.currs[2].minamount=1.0
market.currs[2].withfee=0.1
Run Code Online (Sandbox Code Playgroud)

我然后尝试注入MarketConfig.java这样:

@PropertySource("classpath:config.properties")
@ConfigurationProperties(prefix = "market")
@Validated
public class MarketConfig {

    // the configured currencies
    private List<MarketCurrency> currs;

    // the configured currencypairs
    private List<MarketCurrencypair> curpairs;

  /* static classes */
  public static class MarketCurrency {
    String name;
    String symbol;
    double minamount;
    // getter and setter ommitted
  }
  public static class MarketCurrencypair {
    String name;
    String symbol;
    double minamount;
    double …
Run Code Online (Sandbox Code Playgroud)

java configuration spring properties-file spring-boot

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

替换application.properties以外的Spring属性文件中的环境变量

Spring Boot将使用相应的环境变量自动解析文件中的任何${ENV}占位符application.properties.

但是,当我quartz.properties通过PropertiesFactoryBeanQuartz配置文件提供时,这种解决方案不会发生.

@Bean
public Properties getQuartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}
Run Code Online (Sandbox Code Playgroud)

有没有Spring方法在不使用外部库的情况下替换属性文件中的这些环境变量?

java spring properties-file spring-boot

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