What going wrong in using PropertiesConfiguration?

只谈情不闲聊 提交于 2019-12-13 16:18:23

问题


For updating in my .properties file I am using Apache Commons Configuration's PropertiesConfiguration. But as I am using the code as :

try {
        PropertiesConfiguration properties = new PropertiesConfiguration("dao.properties");

    } catch (ConfigurationException ex) {

    }

I am getting this error:

incompatible types
required: java.lang.Throwable
found:    org.apache.commons.configuration.ConfigurationException

What is going wrong here? I am using it first for the first time.

P.S.: Is there any comparatively equivalent or better library available for handling .properties ?


回答1:


You are using incompatible versions of the library. Try:

  • commons-configuration-1.7
  • commons-collections-3.2.1
  • commons-lang-2.6
  • commons-logging-1.1.1

It works for me.




回答2:


I had the same problem and this post saved my day; wanted to share a bit more that I learned in the process:

Try just adding the commons-lang library before you add all four mentioned by Sergio. My code looks remarkably similar the example referenced in the question and I found those two libraries satisfied the dependencies needed.

@Haroldo - you're correct in the library mismatch. Tried commons-lang 3.3 first with no success. Verified that commons-configuration-1.9 and commons-lang-2.6 play well together.

@Asif - is there a particular reason that you need the added functionality of the Apache library? I've found that the java.util.Properties class works just fine for most of my applications, and doesn't require the additional libraries. Of course, that depends on what you are doing with the values returned.




回答3:


Your reference to "dao.properties" suggests to me that you are deploying your code in a web service environment. In that case, you need to ensure that the libraries the web service loads and the libraries you are referencing are exactly the same (at least the same version), as differences can cause errors like the one you encountered -- the class loaded by the webservice classloader is different than the one loaded by your app's classloader, hence the exception.



来源:https://stackoverflow.com/questions/9928574/what-going-wrong-in-using-propertiesconfiguration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!