【问题标题】:Unable to resolve the error: Application failed to start with classpath:无法解决错误:应用程序无法使用类路径启动:
【发布时间】:2022-01-06 15:00:44
【问题描述】:

运行 java spring boot 应用程序时出现以下错误。 首先,我转到主包中的 application.java 文件并作为 Java 应用程序运行。

```Error:
Application failed to start with classpath: ...
36:45.59 [main] ERROR org.springframework.boot.SpringApplication - Application run failed. 
com.amazonaws.SdkClientException : Unable to find region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.```

以下是 pom.xml 文件:

```<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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- we are extending from this project POM which means we get everything 
        that this pom has (inheritance) -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
    </parent>

    <dependencies>
        <!-- base spring functionality -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <!-- MySQL Connector -->
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- nekohtml dependency -->
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
        </dependency>
        <!-- auto config for spring stuff -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- JPA Java Persistence API, interface for saving/fetching data -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- Dev tools for no-restart, etc -->
        
        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency> -->
        
        <!-- Swagger Dependencies -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <!-- Thymeleaf email dependency -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!--Health Check -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--Admin -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.1.6</version>
        </dependency>
        <!--Security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <!-- LiquiBase -->
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
        <!-- LiquiBase -->

        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.4.1</version>
        </dependency>
        
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.11.600</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <...>
        <plugins>
            <plugin>
                <groupId>external.atlassian.jgitflow</groupId>
                <artifactId>jgitflow-maven-plugin</artifactId>
                <version>1.0-m5.1</version>
                <configuration>
                    <!-- No Maven deploy. -->
                    <noDeploy>true</noDeploy>
                    <!-- No merge, we'll do manual by pull request -->
                    <noReleaseMerge>true</noReleaseMerge>
                    <!-- No merge, we'll do manual by pull request -->
                    <noFeatureMerge>true</noFeatureMerge>
                    <!-- Keep branch for manual pull request -->
                    <keepBranch>true</keepBranch>
                    <flowInitContext>
                        <masterBranchName>stage</masterBranchName>
                        <developBranchName>develop</developBranchName>
                        <featureBranchPrefix>feature-</featureBranchPrefix>
                        <releaseBranchPrefix>release-</releaseBranchPrefix>
                        <hotfixBranchPrefix>hotfix-</hotfixBranchPrefix>
                        <versionTagPrefix>version-</versionTagPrefix>
                    </flowInitContext>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <!-- look online for options like specify directory -->
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <useSystemClassLoader>false</useSystemClassLoader>
                </configuration>
            </plugin>
            <!-- liquibase -->

            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <propertyFile>src/test/resources/liquibaseMaven.properties</propertyFile>
                </configuration>
                <!-- -->
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate4</artifactId>
                        <version>3.5</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>4.1.7.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.data</groupId>
                        <artifactId>spring-data-jpa</artifactId>
                        <version>1.7.3.RELEASE</version>
                    </dependency>
                </dependencies>
                <!-- -->
            </plugin>
            <!-- liquibase -->

        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
        <repository>
            <id>....</id>
            <name>AWS Release Repository</name>
            <url>s3://.../...</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>```

下面是application.properties文件:

```spring.profiles.active=local

awsParameterStorePropertySource.enabled = true

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

api.s3.accessKey=...
api.s3.secretKey=...```

在进行故障排除时,以下是我尝试过的事情:

  1. Maven 清理、Maven 安装、Maven 构建
  2. 从您的计算机中删除 .m2 文件 检查 settings.xml 文件 重新安装 .m2 文件并确保路径正确。
  3. 卸载并重新安装 eclipse
  4. 仔细检查 AWS 密钥
  5. 从您的计算机中完全删除 repo 并重新克隆
  6. 检查 AWS 中的区域,
  7. 检查您的 AWS CLI 配置中的凭证是否匹配
  8. 在 S3 存储桶中授予访问权限

你们对这个错误有什么建议吗?

【问题讨论】:

标签: java spring amazon-web-services spring-boot maven


【解决方案1】:

我看到您正在尝试在 application.properties 中定义您的信誉。相反 - 尝试根据此处的 AWS Java 开发指南设置您的密钥:

Using credentials

我们在各种 AWS 服务指南中提供了许多 Spring BOOT 示例。这些示例应用通过将凭据放入名为 credentials 的文件中来处理凭据:C:\Users.aws\credentials(或对于 Linux - ~/.aws/credentials)。

要了解如何编写使用 AWS 服务的成功 Spring BOOT 应用程序,请参阅 Amazon Simple Notification Service Guide 中的此示例,该示例展示了如何开发 Spring BOOT具有 Sub/Pub 功能的应用:

Build a publish and subscription web application that translates messages

【讨论】:

    猜你喜欢
    • 2011-02-23
    • 2015-12-10
    • 2015-02-02
    • 2018-12-29
    • 2018-03-17
    • 2021-08-06
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    相关资源
    最近更新 更多