0
votes

I have created spring boot application using maven. Where I built a executable jar for application the tried to run it on EC2 instance free tier windows using following command
java -jar com-spring-boot-apps-0.0.1-SNAPSHOT.jar --server.port=8181 -Xdebug

Some it application does not run, it exists with following logs on console.

log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-07-11 13:55:50.762  INFO 2784 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-11 13:55:50.768  INFO 2784 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-11 13:55:50.800  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.3].
2018-07-11 13:55:50.803  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2018-07-11 13:55:50.805  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2018-07-11 13:55:52.060  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.0.2o  27 Mar 2018]
2018-07-11 13:55:52.402  INFO 2784 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-11 13:55:52.532  INFO 2784 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

Exception :-

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'regionProvider': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.region.StaticRegionProvider]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: The region 'ap-south-1a' is not a valid region!
6
I had a similar problem due to a transitive dependencies to commons-logging. Check if you have commons-logging into your dependencies ad than if you don't need it exclude it. This way you should at leaxt see the error - rick
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'regionProvider': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.region.StaticRegionProvider]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: The region 'ap-south-1a' is not a valid region! - Prasad S Deshpande
now I'm out of my competence, I never played with AWS. Did you had to exclude coomons-logging in the end or you have found another way to log? - rick

6 Answers

1
votes

commons-logging has conflict with log4j. I have faced this multiple times and everytime excluding commons-logging helped me fixing this problem. Recommend check dependency tree.

mvn dependency:tree > module-dependency.txt

Then exclude commons-loggin whereever you see

            <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache</groupId>
                <artifactId>commons-io</artifactId>
            </exclusion>
        </exclusions>
0
votes

You can shutdown the application properly via JMX or HTTP if the endpoint is enabled (add endpoints.shutdown.enabled=true to your application.properties file).

/shutdown - Lets the application be gracefully shutdown. (not enabled by default).

From the Spring boot documentation

0
votes

The region "ap-south-1a" is the incorrect region. It should be "ap-south-1" in my opinion. You can check the config file in .aws dir to see if region is correctly set. Also check if the environment variable AWS_DEFAULT_REGION is correct if set.

https://docs.aws.amazon.com/general/latest/gr/rande.html

0
votes

It worked for me after removing cloud.aws.region.static=ap-south-1a from application.properties and pom.xml properties.

But at the same time if I remove this property from my local machine project setting it fails with following error.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amazonS3': Invocation of init method failed; nested exception is java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
0
votes

In my case, the logging framework was missing in the pom.xml file. I was using spring-boot-starter-parent version 2.2.5.RELEASE. To solve the problem of application not started, in the pom.xml I have added, the followings :

<dependency>
        <artifactId>logback-classic</artifactId>
        <groupId>ch.qos.logback</groupId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>