java - Spring Boot找不到主类多模块

标签 java spring-mvc spring-boot gradle groovy

我很难告诉 Spring Main 类的位置。到目前为止,我只设法正确指定它在图片服务模块中的位置(即图片服务/src/main/com.bachdiff.application/Application.java)

这是文件结构。

This is the file structure.

这是主要的 gradle 文件。

       buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
        }
    }

  plugins {
      id 'java'
      id 'java-library'
      id 'idea'
      id "org.springframework.boot" version "2.0.2.RELEASE"
      id "io.spring.dependency-management" version "1.0.5.RELEASE"
  }

    bootJar {
        baseName = 'com.bachadiff.pictures-service'
        version = '0.1.0'
        mainClassName = 'com.bachadiff.application.Application'

    }
    version = '0.1.0'

    repositories {
        mavenCentral()
    }

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    ext.common = [
            spring_web  : 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE',
            spring_rest : 'org.springframework.boot:spring-boot-starter-data-rest:2.0.2.RELEASE',
            spring_mongo: 'org.springframework.boot:spring-boot-starter-data-mongodb:2.0.2.RELEASE',
            spring_test : 'org.springframework.boot:spring-boot-starter-test'
    ]

    ext.test = [
            junit: 'junit:junit:4.12'
    ]

    dependencies {
        api 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE'
        api 'org.springframework.boot:spring-boot-starter-data-rest:2.0.2.RELEASE'
        api 'org.springframework.boot:spring-boot-starter-data-mongodb:2.0.2.RELEASE'
        compile project(':pictures-service-impl')
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
    }

最佳答案

mainClassName应该由包和类名本身组成,所以在你的情况下应该是:

mainClassName = 'com.bachadiff.application.Application'

既然你说你有一个多项目构建,你应该把它放在 build.gradle对于pictures-service-application项目

关于java - Spring Boot找不到主类多模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50477773/

相关文章:

java - Java中的UDP数据包路由

spring - 我可以使用 spring boot 数据源来获取连接对象,以便手动将其与 conn.executeQuery() 一起使用吗?

spring-mvc - SpringMVC生命周期——全貌

java - Spring Boot 2.2 activemq jetty冲突

Java- Hibernate 生成的 Java Bean 中的 ToString() 导致 StackOverflowError

java - 如何解决图书馆的密封违规问题?密封违规 : package org. lwjgl.opengl 被密封

java - Spring Boot 应用程序意外退出并显示 "Killed"

java - 部署在 spring-cloud-dataflow-server 中的服务如何连接到另一个数据库而不是数据流服务器使用的数据库?

Java 字符增量

java - Spring Security - 白名单IP范围