Error Running Spring Boot Application from Docker Container

时间:2018-07-25 05:03:45

标签: mysql docker spring-boot

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 个答案:

答案 0 :(得分:0)

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.

答案 1 :(得分:0)

您设置了两个入口点。一个通过docker文件,另一个通过maven插件。我相信这可能会引起问题。

尝试一下:

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

您只需为Docker文件设置一个参数-> JAR_FILE ,具体取决于您的Docker文件。

答案 2 :(得分:0)

已解决。只需将依赖项更改为

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

来自

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