【问题标题】:Spring Boot Can't find main class Multi moduleSpring Boot找不到主类多模块
【发布时间】:2018-11-01 19:37:30
【问题描述】:

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

这是文件结构。

这是主要的 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'
    }

【问题讨论】:

  • 我对spring一点也不熟悉,但是你试过用mainClassName = 'com.bachadiff.application.Application'代替吗?您可以通过右键单击所选类然后选择“复制参考”来获取您需要使用的字符串
  • 我可以得到字符串,它和你说的完全一样,但是当我把它放在主要的 build.gradle 中时它仍然找不到它。 (mainClassName = com.bachdiff.application.Application,或 mainClassName = pictures-service-applications.com.bachadiff.application.Application)

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


【解决方案1】:

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

mainClassName = 'com.bachadiff.application.Application'

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

【讨论】:

  • 当我说多模块时,我指的是 Intellij 模块。 (jetbrains.com/help/idea/creating-and-managing-modules.html)。当我将 mainClassName 放在应用程序模块中时,gradlew build 失败,manifest 属性不能为 null
  • 你使用的是 Spring Boot 1 还是 2?
  • 我使用的是 Spring Boot 2
  • 你可以尝试使用springBoot 任务来配置它吗:springBoot { mainClassName = 'com.bachdiff.application.Application' }
  • 我得到一个编译错误,说它找不到 mainClassName 是一个未知属性。
猜你喜欢
  • 2018-01-30
  • 2015-04-11
  • 2016-01-10
  • 2019-07-05
  • 2018-05-09
  • 2019-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多