0
votes

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 t o 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>
3
Can you share your dockerFile ?piy26
Added the dockerfile.Sunil
Dependencies for ExpressionFactory is missing in your Docker COntainerMyTwoCents
Is your app.jar a fat jar. I mean please make sure if it contains all the dependencies. Make sure you use one of the maven/gradle plugin that assembles all the jar in the single jar.piy26
I've also tried with the maven plugin added in the pom file with the same result. I guess I'm missing something.Sunil

3 Answers

0
votes

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.

0
votes

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.

0
votes

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>