A simple Apache-commons configuration example throws a ConfigurationRuntimeException

I am trying to test a very simple example specified in the Apache-commons library configuration user guide regarding declaring and creating beans, I copied the code in the example almost word for word, and yet I get a ConfigurationRuntimeException (this is after overcoming another exception, see this question )

Here is the xml file that I use - windowcongif.xml :

 <?xml version="1.0" encoding="ISO-8859-1" ?> <config> <gui> <windowManager config-class="test.DefaultWindowManager" closable="false" resizable="true" defaultWidth="400" defaultHeight="250"> </windowManager> </gui> </config> 

Here is the code in the WindowManager.java file:

 package test; public interface WindowManager {} 

Here is the code in the DefaultWindowManager.java file:

 package test; public class DefaultWindowManager implements WindowManager { private boolean resizable; private boolean closable; private int defaultWidth; private int defaultHeight; } 

Here is the code in Main.java file:

 package test; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.configuration.beanutils.BeanDeclaration; import org.apache.commons.configuration.beanutils.BeanHelper; import org.apache.commons.configuration.beanutils.XMLBeanDeclaration; import org.apache.commons.beanutils.PropertyUtils; public class Main { public static void main(String[] args) throws ConfigurationException { XMLConfiguration config = new XMLConfiguration("windowconfig.xml"); BeanDeclaration decl = new XMLBeanDeclaration(config, "gui.windowManager"); WindowManager wm = (WindowManager) BeanHelper.createBean(decl); } } 

Here is the result at runtime:

 Exception in thread "main" org.apache.commons.configuration.ConfigurationRuntimeException: org.apache.commons.configuration.ConfigurationRuntimeException: Property defaultHeight cannot be set on test.DefaultWindowManager at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:341) at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:358) at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:372) at test.Main.main(Main.java:24) Caused by: org.apache.commons.configuration.ConfigurationRuntimeException: Property defaultHeight cannot be set on test.DefaultWindowManager at org.apache.commons.configuration.beanutils.BeanHelper.initProperty(BeanHelper.java:271) at org.apache.commons.configuration.beanutils.BeanHelper.initBeanProperties(BeanHelper.java:229) at org.apache.commons.configuration.beanutils.BeanHelper.initBean(BeanHelper.java:166) at org.apache.commons.configuration.beanutils.DefaultBeanFactory.initBeanInstance(DefaultBeanFactory.java:108) at org.apache.commons.configuration.beanutils.DefaultBeanFactory.createBean(DefaultBeanFactory.java:64) at org.apache.commons.configuration.beanutils.BeanHelper.createBean(BeanHelper.java:336) ... 3 more 

How can I make this simple example?

I am using version 1.9 of the commons-configuration package and version 1.8.3 of the commons-beanutils package, automatically imported by IntelliJ IDEA after placing the dependencies in the pom.xml file and version 1.7.0_17 from java, it works on Windows 8 64bit.

+2
source share
1 answer

If you are using JavaBeans, you will need to add an installer for each field that you want to install.

I suggest using add setter and getter in IntelliJ for these fields.

The example indicates

 // getters and setters ommitted, also the WindowManager methods 
+4
source

All Articles