简体   繁体   中英

Error Running Spring Boot Application from Docker Container

I'm trying to run a Spring Boot application inside the Docker Container, but I'm getting the following issue. However, I do not face any issues if I run the application through STS.

ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - can celling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.Re questMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCrea tionException: Error creating bean with name 'mvcValidator' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWe bMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.Validator]: Factory method 'mvcValidator' threw exception; nested exception is javax.validation.ValidationEx ception: HV000183: Unable to initialize 'javax.el.ExpressionFactory'. Check that you have the EL dependencies on the classpath, or use ParameterMessageInt erpolator instead

Dockerfile--

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Pom.xml--

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>

    <configuration>
        <imageName>genaaqua/web-project</imageName>
        <baseImage>java:8</baseImage>
        <entryPoint>
            ["java", "-jar", "/${project.build.finalName}.jar"]
        </entryPoint>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

Any properly packed spring boot application should be able to start with: java -jar app.jar

So, first of all make sure you're able to run the application "Outside" the docker container, because the chances are that the docker is not really relevant here, and the application is just not packaged properly.

In the "target"/"build" folder (depending on the build tool) locate the app.jar and run it without any docker.

You have two entry points set. One via docker file and other via maven plugin. I believe that can cause issue.

try this:

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.3.6</version>
       <configuration>
       <repository>${docker.image.prefix}/${project.artifactId}</repository>
       <buildArgs>
          <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
       </buildArgs>
       </configuration>
</plugin>

You only need one argument set for the Docker file -> JAR_FILE as per your docker file.

Resolved. Just needed to change the dependency to

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.el</artifactId>
    <version>3.0.1-b08</version>
</dependency>

from

<dependency>
    <groupId>javax.el</groupId>
    <artifactId>el-api</artifactId>
    <version>2.2</version>
</dependency>

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