gpt4 book ai didi

java - 尝试使用 commons-configuration2 将配置添加到 CompositeConfiguration 时出现 ClassNotFoundException

转载 作者:行者123 更新时间:2023-12-02 11:21:49 27 4
gpt4 key购买 nike

我正在使用 org.apache.commons:commons-configuration2 加载和合并来自不同来源的配置:

val root = CompositeConfiguration()
root.addConfiguration(SystemConfiguration())

val configurations = Configurations()


root.addConfiguration(configurations.properties("defaults.properties"))

我的问题是,每当我运行此代码时,我都会遇到异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanIntrospector at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.sun.proxy.$Proxy0.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:739) at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:294) at org.apache.commons.configuration2.builder.fluent.Parameters.fileBased(Parameters.java:185) at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:602) at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:638) at org.apache.commons.configuration2.builder.fluent.Configurations.fileBasedBuilder(Configurations.java:164) at org.apache.commons.configuration2.builder.fluent.Configurations.propertiesBuilder(Configurations.java:264) at org.apache.commons.configuration2.builder.fluent.Configurations.properties(Configurations.java:318) at io.sspinc.datahub.sparkapp.MainKt.main(main.kt:18) Caused by: java.lang.ClassNotFoundException: org.apache.commons.beanutils.BeanIntrospector at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

它说找不到org.apache.commons.beanutils.BeanIntrospector。如果我将commons-beanutils:commons-beanutils:1.9.3添加到类路径中,问题就解决了,但主要问题是我在托管环境中使用Apache Spark 2.3.0 (Databricks) 并且它附带 commons-beanutils:1.7.0 所以我无法对 beanutils 版本做任何事情。

如何解决这个问题?

最佳答案

如果您只需要commons-configuration 形式的复合配置功能,您可能需要尝试使用commons-configuration:commons-configuration:1.10commons-configuration。它的工作原理如下:

val root = CompositeConfiguration()
root.addConfiguration(SystemConfiguration())

root.addConfiguration(PropertiesConfiguration("defaults.properties"))

根据 their documentation,配置 2 无法与 1.7.0 bean utils 一起使用.

关于java - 尝试使用 commons-configuration2 将配置添加到 CompositeConfiguration 时出现 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49858432/

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