Spring Boot无法找到主类Multi模块

时间:2018-05-22 23:23:54

标签: java spring-mvc spring-boot gradle groovy

我很难告诉Spring Main类的位置。到目前为止,我只是设法正确指定它在图片服务模块中的位置(即pictures-service / src / main / com.bachadiff.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'
    }

1 个答案:

答案 0 :(得分:0)

mainClassName应该包含在包和类名本身之外,所以在你的情况下应该是:

mainClassName = 'com.bachadiff.application.Application'

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