简体   繁体   中英

Unable to resolve the error: Application failed to start with classpath:

I am getting the following error when I run my java spring boot application. To start this I go to my application.java file in the main package and run as Java application.

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.

Following is the pom.xml file:

<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>

Following is application.properties file:

spring.profiles.active=local

awsParameterStorePropertySource.enabled = true

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

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

While troubleshooting, here are the things that I have tried:

  1. maven clean, maven install, maven build
  2. removing the.m2 file from your computer checking the settings.xml file reinstalling the.m2 file and making sure the path is correct.
  3. uninstalling and reinstalling eclipse
  4. double checking the AWS keys
  5. Deleting the repo entirely from your computer and recloning
  6. checking the region in AWS,
  7. checking that the credentials match in your AWS CLI config
  8. giving access in S3 buckets

Do you guys have any recommendation for this error?

I see you are trying to define your creds in application.properties. Instead - try setting up your keys according to the AWS Java DEV Guide here:

Using credentials

We have many Spring BOOT examples throughout various AWS Service guides. These example apps handle creds by putting them in a file named credentials here: C:\Users<yourUserName>.aws\credentials (or for Linux - ~/.aws/credentials).

To learn how to write a successful Spring BOOT app that uses AWS services, see this example in the Amazon Simple Notification Service Guide that shows how to develop a Spring BOOT app that has Sub/Pub functionality:

Build a publish and subscription web application that translates messages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM