gpt4 book ai didi

java - 尝试设置 PropertiesConfiguration 时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-30 02:28:46 25 4
gpt4 key购买 nike

我正在尝试设置一个FileBasedConfigurationBuilder,以便我可以使用PropertiesConfiguration,但我收到一个NoClassDefFoundError。这是我的代码

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-beanutils) 中的 apache commons bean utils jar(其中包含 BeanIntrospector 类),请确保将其添加到解决问题。

您可以从maven存储库下载jar:https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils

关于java - 尝试设置 PropertiesConfiguration 时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44802350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com