为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

三国纷争 2022-06-04 16:11:54
以下场景:场景: 我在 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:8ENTRYPOINT ["java", "-jar", "/UserManagementService-0.0.1-SNAPSHOT.jar"]
查看完整描述

1 回答

?
森栏

TA贡献1810条经验 获得超5个赞

它会导致相同的堆栈跟踪。


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

isfiedDependencyException: 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 'doctorContr

oller': 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 c

ircular reference?

更新:


POM.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>


    <groupId>com.usermanagement</groupId>

    <artifactId>UserManagementService</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <packaging>jar</packaging>


    <name>UserManagementService</name>

    <description>Microservice for usermanagement</description>



    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.1.0.RELEASE</version>

        <relativePath /> <!-- lookup parent from repository -->

    </parent>


    <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <java.version>1.8</java.version>

    </properties>


    <dependencies>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-security</artifactId>

        </dependency>


        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-actuator</artifactId>

        </dependency>


        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-hateoas</artifactId>

        </dependency>


        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>


        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-devtools</artifactId>

            <scope>runtime</scope>

        </dependency>


        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>


        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-data-jpa</artifactId>

        </dependency>

        <dependency>

            <groupId>org.apache.tomcat.embed</groupId>

            <artifactId>tomcat-embed-jasper</artifactId>

        </dependency>

        <dependency>

            <groupId>javax.servlet</groupId>

            <artifactId>jstl</artifactId>

        </dependency>

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

        </dependency>

        <dependency>

            <groupId>org.webjars</groupId>

            <artifactId>jquery</artifactId>

            <version>3.2.1</version>

        </dependency>

        <dependency>

            <groupId>org.webjars</groupId>

            <artifactId>bootstrap</artifactId>

            <version>3.3.5</version>

        </dependency>

        <dependency>

            <groupId>log4j</groupId>

            <artifactId>log4j</artifactId>

            <version>1.2.17</version>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter</artifactId>

            <exclusions>

                <exclusion>

                    <groupId>org.springframework.boot</groupId>

                    <artifactId>spring-boot-starter-logging</artifactId>

                </exclusion>

            </exclusions>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-log4j</artifactId>

            <version>1.2.8.RELEASE</version>

        </dependency>


        <dependency>

            <groupId>javax.json</groupId>

            <artifactId>javax.json-api</artifactId>   

        </dependency>


                <!-- https://mvnrepository.com/artifact/org.json/json -->

        <dependency>

            <groupId>org.json</groupId>

            <artifactId>json</artifactId>

            <version>20180813</version>

        </dependency>


        <!-- <dependency>

            <groupId>org.glassfish</groupId>

            <artifactId>javax.json</artifactId>

           <version>1.1</version>

        </dependency> -->

        <dependency>

            <groupId>org.glassfish</groupId>

            <artifactId>javax.el</artifactId>

        </dependency>



    </dependencies>

    <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>


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


        </plugins>

    </build>



</project>



查看完整回答
反对 回复 2022-06-04
  • 1 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信