Spring Boot 使用Docker compose时,Sping Boot 应用程序“没有主清单属性”

j8ag8udp  于 2023-10-16  发布在  Spring
关注(0)|答案(1)|浏览(126)

我正在处理一个简单的场景,我正在启动一个spring Boot 应用程序,在此之前,我正在剥离mysql容器。我正在使用docker-compose,但我得到了no main manifest attribute错误。以下是我的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.springlearn</groupId>
    <artifactId>learnspringdb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>usermanagement</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
        <start-class>om.springlearn.learnspringdb.UsermanagementApplication</start-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

下面是docker-compose文件。

version: '3'
services:
  app:
    container_name: spring_boot_app
    build: ./
    ports:
     - "8080:8080"
    depends_on:
      - mysql
    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/user_management

  mysql:
    image: mysql:8.1.0
    ports:
      - "3307:3036"
    environment:
      MYSQL_ROOT_USER: root
      MYSQL_ROOT_PASSWORD: password

我在谷歌上搜索并对pom.xml进行了调整,但仍然不起作用。
如果我单独启动spring Boot 应用程序,那么它工作正常,但只在docker-compose中出错。
有没有想过这里缺少了什么?
我的github repo:https://github.com/algouser/learnspringdb

ha5z0ras

ha5z0ras1#

1.你是否在某个地方有一个注解为@SpringBootApplication的类给出了main方法?

@SpringBootApplication
@ComponentScan(basePackages={"my.packages"})
public class Application {
   public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
   }
}

1.此外,我不知道这是否有区别,但我以这种方式调用插件,并向其添加executable = true配置:

<execution>
    <id>executable-jar</id>
    <phase>install</phase>

    <goals>
        <goal>repackage</goal>
    </goals>

    <configuration>
       <executable>true</executable>
    </configuration>
</execution>

相关问题