我正在使用具有以下依赖项的 AWS Java S3 SDK。
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.155</version>
</dependency>
Java 的一切都运行良好:
BasicAWSCredentials credentials = new BasicAWSCredentials(key, secret);
AmazonS3 s3 = AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
如果我尝试通过 Groovy 脚本执行完全相同的操作:
def credentials = new BasicAWSCredentials(key, secret);
def s3 = AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(s3region)
.build()
我遇到异常:
Caught: javax.xml.stream.FactoryConfigurationError:
Provider com.bea.xml.stream.MXParserFactory not found
将 stax 依赖项显式添加到我的 .pom 中会导致其他地方出现冲突的类。
Groovy 有什么技巧吗?
最佳答案
尝试排除 stax-api:
@GrabConfig(systemClassLoader = true)
@Grab('stax:stax:1.2.0')
@GrabExclude('stax:stax-api')
仅仅引入 stax 就给了我:
java.lang.LinkageError: loader constraint violation: when resolving field "DATETIME" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type, javax/xml/namespace/QName, have different Class objects for that type
stax-api 依赖项有一个 javax.xml.namespace.QName 类,该类与 JRE 提供的类冲突 ( https://docs.oracle.com/javase/7/docs/api/javax/xml/namespace/QName.html )。
关于java - 来自 Groovy 脚本的 AWS Java SDK - 未找到提供程序 com.bea.xml.stream.MXParserFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44769904/