properties-file

Why does Java ignore the first line of a .properties file?

Deadly 提交于 2019-11-30 07:31:51
问题 I was working with an app that loads a .properties file with java.util.Properties like this: Properties _properties = new Properties(); _properties.load(new FileInputStream("app.properties")); The properties file (initially) was this: app=myApp dbLogin=myDbLogin version=0.9.8.10 server=1 freq=10000 stateGap=360000 The strange thing was that when I called _properties.getProperty("app") , it always returned null , however I could load all of the other properties without any issues. I solved the

Eclipse wrong Java properties UTF-8 encoding

空扰寡人 提交于 2019-11-30 05:58:42
I have a JavaEE project, in which I use message properties files. The encoding of those file is set to UTF-8. In the file I use the german umlauts like ä , ö , ü . The problem is, sometimes those characters are replaced with unicode like \uFFFD\uFFFD , but not for every character. Now, I have a case where ä and ü are both replaced with \uFFFD\uFFFD , but not for every occurring of ä and ü . The Git diff shows me something like this: mail.adresses=E-Mail hinzufügen: -mail.adresses.multiple=E-Mails durch Kommata getrennt hinzufügen. +mail.adresses.multiple=E-Mails durch Kommata getrennt hinzuf

Spring Property Injection in a final attribute @Value - Java

别来无恙 提交于 2019-11-30 04:19:47
A simple question on Spring injection from a properties file for a final attribute. I have a properties file which I want to store a file path in. Generally when I use properties files I setup class attributes using something like this: private @Value("#{someProps['prop.field']}") String someAttrib ; Then in my spring.xml I would have something like: <util:properties id="someProps" location="classpath:/META-INF/properties/somePropFile.properties" /> This works well, is simple and makes code nice and neat. But I'm not sure what is the neatest pattern to use when trying to inject properties

How to append new data to existing data in properties file?

99封情书 提交于 2019-11-30 03:56:46
问题 I am using following code for writing data to properties file public void WritePropertiesFile(String key, String data) { Properties configProperty = new Properties(); configProperty.setProperty(key, data); File file = new File("D:\\Helper.properties"); FileOutputStream fileOut = new FileOutputStream(file,true); configProperty.store(fileOut, "sample properties"); fileOut.close(); } I am calling the above method 3 times as follows: help.WritePropertiesFile("appwrite1","write1"); help

PropertyPlaceholderConfigurer and environment variables in .properties files

南楼画角 提交于 2019-11-30 02:31:29
I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties' values from .properties file. Main and test source folders have separate .properties file. The issue is that I need to use environment variables in .properties file. But when I do it in the following way: property.name=${env.SYSTEM_PROPERTY} I'm getting the following error: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'beanName' defined in class path resource [com/example/applicationContext.xml]: Could not resolve placeholder 'env.SYSTEM_PROPERTY'

Override Properties file in Spring WebApp at Runtime

☆樱花仙子☆ 提交于 2019-11-29 17:15:10
I am loading properties file in my Spring WebApplication using PropertyPlaceholderConfigurer as below: <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:db.properties</value> <value>classpath:mail.properties</value> </list> </property> </bean> Now, I want to override some of the properties from mail.properties , so I created an additional entry in my application-context file reading this post , as follows: <context:property-placeholder location="file:override.properties" order="-1" ignore-unresolvable="true

I want to read spring properties file that has a map of maps

女生的网名这么多〃 提交于 2019-11-29 16:52:07
I want to have a property like below that is a map of maps propertymap = { key1:'{subkey1:'subvalue1',subkey2:'subvalue2'}', key2:'{subkey3:'subvalue3',subkey4:'subvalue4'}' } @Value("#{${propertymap}}") private Map<String,Map<String,String>> propertymap; used code like above in my config class but got error. please let me know if there is a way to do this. Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Map nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception

How to get properties file from /WEB-INF folder in JSF?

浪子不回头ぞ 提交于 2019-11-29 08:00:47
I have some properties file in /WEB-INF . And I want to load it in a JSF managed bean. Is there any way to do that? BalusC Use either ExternalContext#getResource() or ExternalContext#getResourceAsStream() wherein you pass the webcontent-relative path. E.g.: ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); Properties properties = new Properties(); // ... properties.load(externalContext.getResourceAsStream("/WEB-INF/file.properties")); This delegates under the covers to ServletContext#getResource() / getResourceAsStream() . See also: Where to place and

Why does Java ignore the first line of a .properties file?

烈酒焚心 提交于 2019-11-29 04:34:36
I was working with an app that loads a .properties file with java.util.Properties like this: Properties _properties = new Properties(); _properties.load(new FileInputStream("app.properties")); The properties file (initially) was this: app=myApp dbLogin=myDbLogin version=0.9.8.10 server=1 freq=10000 stateGap=360000 The strange thing was that when I called _properties.getProperty("app") , it always returned null , however I could load all of the other properties without any issues. I solved the problem by adding a comment to the top of the properties file, then everything worked fine. My

Write/Update properties file value in spring

梦想的初衷 提交于 2019-11-29 03:50:22
I have some requirement where I want to write/update the value in the properties file I am using the my spring application. I have googled it but I have not found a direct way of doing it using Spring. Does any one aware of how to do it or is there any best way to do it. Thanks in advance. You can achieve that like this : public void saveParamChanges() { try { // create and set properties into properties object Properties props = new Properties(); props.setProperty("Prop1", "toto"); props.setProperty("Prop2", "test"); props.setProperty("Prop3", "tata"); // get or create the file File f = new