码头工人服务器找不到主类

时间:2020-01-13 08:48:57

标签: java spring-boot maven docker

我在功能正常的spring-boot + mysql + react js应用程序上遇到问题。(在尝试将其部署到docker之前,我已经对其进行了测试)。

当我给出命令“ docker-compose up -d”时,它可以工作,我可以看到容器,可以访问前端,但是后端/服务器中的任何请求均被拒绝。

我查看了服务器日志并得到错误:Error: Could not find or load main class com.example.springdemo.SpringDemoApplication

我的dockerfile:

#### Stage 1: Build the application
FROM openjdk:8-jdk-alpine as build

# Set the current working directory inside the image
WORKDIR /app

# Copy maven executable to the image
#COPY mvnw .
#COPY .mvn .mvn

# Copy the pom.xml file
COPY pom.xml .

# Build all the dependencies in preparation to go offline. 
# This is a separate step so the dependencies will be cached unless 
# the pom.xml file has changed.
#RUN ./mvnw dependency:go-offline -B

# Copy the project source
COPY src src

# Package the application
#RUN ./mvnw package -DskipTests
#RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

#### Stage 2: A minimal docker image with command to run the app 
FROM openjdk:8-jre-alpine

#ARG DEPENDENCY=/app/target/dependency

# Copy project dependencies from the build stage
#COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
#COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
#COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.springdemo.SpringDemoApplication"]

我检查了主的路径是否正确。我不知道为什么找不到主班。

后端代码位于https://github.com/Diana-Ioana/docker_app,与docker-compose.yml文件和后端的Dockerfile一起使用。 我使用docker工具箱(不是docker桌面,我有WIN 10 HOME)

1 个答案:

答案 0 :(得分:0)

据我所知,您仅复制源,因此尽管所有路径都是正确的,但没有什么可以在其上调用“ java”的(如果指定了-jar,则应在.class或.jar上调用)。

如果您不熟悉docker / spring boot,spring io对于在docker中运行spring boot有很好的指导,因此值得一试:Spring Boot with Docker