[Guice/ErrorInCustomProvider]: NoSuchMethodError: 'void ConstructorConstructor.<init>(Map)' at GsonModule.provideGson(GsonModule.java:99)

问题描述 投票:0回答:0

我有一个使用 jClouds 的 Spring Boot 项目,它有 2 个类,如下所示:

@Configuration
public class S3Config {

  @Value("${amazon.s3.access-key}")
  private String accessKey;

  @Value("${amazon.s3.secret-key}")
  private String secretKey;

  @Value("${amazon.s3.region}")
  private String region;

  @Value("${amazon.s3.bucket-name}")
  private String bucketName;

  @Bean
  public BlobStoreContext context() {
    Properties properties = new Properties();
    properties.setProperty(S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
    BlobStoreContext context = ContextBuilder.newBuilder("aws-s3")
      .credentials(accessKey, secretKey)
      .endpoint("https://s3." + region + ".amazonaws.com")
      .overrides(properties)
      .buildView(BlobStoreContext.class);
    return context;
  }

  @Bean
  public BlobStore blobStore() {
    return context().getBlobStore();
  }

  public void createBucket(String bucketName) {
    BlobStoreContext context = context().unwrap();
    S3BlobStore s3BlobStore = S3BlobStore.class.cast(context.getBlobStore());
    s3BlobStore.createContainerInLocation(null, bucketName);
  }

  public List<String> listBucket() {
    BlobStoreContext context = context().unwrap();
    S3BlobStore s3BlobStore = S3BlobStore.class.cast(context.getBlobStore());
    PageSet<? extends StorageMetadata> containers = s3BlobStore.list();
    List<String> bucketNames = new ArrayList<>();
    for (StorageMetadata container : containers) {
      bucketNames.add(container.getName());
    }
    return bucketNames;
  }
}

@RestController
@RequestMapping("/s3")
public class S3Controller {

  @Autowired
  private S3Config s3Config;

  @PostMapping("/create-bucket")
  public void createBucket(@RequestParam String bucketName) {
    s3Config.createBucket(bucketName);
  }

  @GetMapping("/list-bucket")
  public List<String> listBucket() {
    return s3Config.listBucket();
  }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.9</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gokhan</groupId>
    <artifactId>jclouds1mv</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>jclouds1mv</name>
    <description>jclouds1mv</description>
    <properties>
        <java.version>17</java.version>
        <jclouds.version>2.5.0</jclouds.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.jclouds</groupId>
            <artifactId>jclouds-blobstore</artifactId>
            <version>${jclouds.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jclouds</groupId>
            <artifactId>jclouds-allblobstore</artifactId>
            <version>${jclouds.version}</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.apache.jclouds/jclouds -->
        <dependency>
            <groupId>org.apache.jclouds</groupId>
            <artifactId>jclouds</artifactId>
            <version>${jclouds.version}</version>
            <type>pom</type>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

当我运行项目时,出现以下错误(实际时间要长得多)

我是初级开发者,看不懂,暂时解决不了这个问题

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'context' defined in class path resource \[com/gokhan/jclouds1mv/config/S3Config.class\]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate \[org.jclouds.blobstore.BlobStoreContext\]: Factory method 'context' threw exception; nested exception is com.google.inject.CreationException: Unable to create injector, see the following errors:

1) \[Guice/ErrorInCustomProvider\]: NoSuchMethodError: 'void ConstructorConstructor.\<init\>(Map)'
   at GsonModule.provideGson(GsonModule.java:99)
   \_ installed by: AWSS3HttpApiModule -\> GsonModule
   at GsonWrapper.\<init\>(GsonWrapper.java:38)
   \_ for 1st parameter
   at GsonWrapper.class(GsonWrapper.java:32)
   while locating GsonWrapper
   while locating Json

有人可以帮忙吗?

在互联网上尝试了一些解决方案,但是大多数都过时了。

spring-boot gson guice jclouds
© www.soinside.com 2019 - 2024. All rights reserved.