尝试设置 PropertiesConfiguration 时出现 NoClassDefFoundError [英] Getting NoClassDefFoundError when trying to set up PropertiesConfiguration
问题描述
我正在尝试设置 FileBasedConfigurationBuilder
以便我可以使用 PropertiesConfiguration
,但我收到了 NoClassDefFoundError
.这是我的代码
I am trying to set up a FileBasedConfigurationBuilder
so that I can work with a PropertiesConfiguration
but I am getting a NoClassDefFoundError
.
Here is my code
public class Config {
private static Properties properties;
private static PropertiesConfiguration config;
public static void setUp(String path) throws ConfigurationException, IOException {
if (config == null) {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
.configure(new Parameters().properties()
.setFileName("myConfig.properties")
.setThrowExceptionOnMissing(true)
.setListDelimiterHandler(new DefaultListDelimiterHandler(','))
.setIncludesAllowed(false));
config = builder.getConfiguration();
File file = new File(path);
FileReader reader = new FileReader(file);
config.read(reader);
}
}
}
和堆栈跟踪:
java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanIntrospector
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.proxy.$Proxy38.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:294)
at org.apache.commons.configuration2.builder.fluent.Parameters.properties(Parameters.java:245)
推荐答案
您似乎错过了类路径 (commons) 中的 apache commons bean utils jar(其中包含
),确保添加它以解决问题.BeanIntrospector
类)-beanutils
It seems you miss the apache commons bean utils jar (which contains the BeanIntrospector
class) from your class path (commons-beanutils
), make sure to add it to fix the issue.
您可以从 Maven 存储库下载 jar:https://mvnrepository.com/工件/commons-beanutils/commons-beanutils
You can downlaod the jar from maven repository: https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils
这篇关于尝试设置 PropertiesConfiguration 时出现 NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!