无法使用 docker 运行 Spring Boot 应用程序

以下场景:


场景: 我在 Eclipse 上使用 Spring Boot 2 开发了一个微服务应用程序。该应用程序工作正常。现在我想用 docker 运行它。此外,图像必须与 mysql 数据库交互。为了构建 docker 镜像,我在 pom.xml 中使用了 com.spotify 插件。


    <plugin>

      <groupId>com.spotify</groupId>

      <artifactId>docker-maven-plugin</artifactId>


      <configuration>

        <imageName>usermanagementservice</imageName>

        <baseImage>openjdk:8-jre-alpine</baseImage>

        <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>

        <!-- copy the service's jar file from target into the root directory of the image --> 

        <resources>

           <resource>

             <targetPath>/</targetPath>

             <directory>${project.build.directory}</directory>

             <include>${project.build.finalName}.jar</include>

           </resource>

        </resources>

      </configuration>

    </plugin>

这会在我的目标文件夹中创建一个 docker 文件和 .jar 文件: Docker 文件:


FROM java:8

ENTRYPOINT ["java", "-jar", "/UserManagementService-0.0.1-SNAPSHOT.jar"]


三国纷争
浏览 107回答 1
1回答

森栏

它会导致相同的堆栈跟踪。Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customBasicAuthenticationFilter': Unsatisfied dependency expressed through field 'mobileUserController'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mobileUserController': Unsatisfied dependency expressed through field 'restTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'doctorController': Unsatisfied dependency expressed through field 'restTemplate'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'restTemplate': Requested bean is currently in creation: Is there an unresolvable circular reference?更新:POM.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"&nbsp; &nbsp; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&nbsp; &nbsp; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">&nbsp; &nbsp; <modelVersion>4.0.0</modelVersion>&nbsp; &nbsp; <groupId>com.usermanagement</groupId>&nbsp; &nbsp; <artifactId>UserManagementService</artifactId>&nbsp; &nbsp; <version>0.0.1-SNAPSHOT</version>&nbsp; &nbsp; <packaging>jar</packaging>&nbsp; &nbsp; <name>UserManagementService</name>&nbsp; &nbsp; <description>Microservice for usermanagement</description>&nbsp; &nbsp; <parent>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-parent</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.1.0.RELEASE</version>&nbsp; &nbsp; &nbsp; &nbsp; <relativePath /> <!-- lookup parent from repository -->&nbsp; &nbsp; </parent>&nbsp; &nbsp; <properties>&nbsp; &nbsp; &nbsp; &nbsp; <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>&nbsp; &nbsp; &nbsp; &nbsp; <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>&nbsp; &nbsp; &nbsp; &nbsp; <java.version>1.8</java.version>&nbsp; &nbsp; </properties>&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-security</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-actuator</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-hateoas</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-web</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-devtools</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <scope>runtime</scope>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-test</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <scope>test</scope>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-data-jpa</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.tomcat.embed</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>tomcat-embed-jasper</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.servlet</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jstl</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>mysql</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>mysql-connector-java</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.webjars</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jquery</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>3.2.1</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.webjars</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>bootstrap</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>3.3.5</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>log4j</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>log4j</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>1.2.17</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-logging</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusions>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-log4j</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>1.2.8.RELEASE</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.json</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>javax.json-api</artifactId>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- https://mvnrepository.com/artifact/org.json/json -->&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.json</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>json</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>20180813</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <!-- <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.glassfish</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>javax.json</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<version>1.1</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency> -->&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.glassfish</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>javax.el</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; </dependencies>&nbsp; &nbsp; <build>&nbsp; &nbsp; &nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.spotify</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>docker-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <imageName>usermanagementservice</imageName>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <baseImage>openjdk:8-jre-alpine</baseImage>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- copy the service's jar file from target into the root directory of the image -->&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <resources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<resource>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<targetPath>/</targetPath>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<directory>${project.build.directory}</directory>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<include>${project.build.finalName}.jar</include>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</resource>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </resources>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; </plugins>&nbsp; &nbsp; </build></project>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java