您说的都对 2021-11-30 16:42 采纳率: 0%
浏览 20
已结题

gradle项目a模块引用b模块,类可以导包成功,但springboot启动则失败

问题遇到的现象和发生背景

gradle创建父子模块进行项目引用,不引用‘service’模块可以启动,引用则启动报找不到类

问题相关代码,请勿粘贴截图

‘app’模块gradle代码

repositories {
    mavenCentral()
}
dependencies {
    implementation  project(':service')
}

‘service’模块gradle代码

repositories {
    mavenCentral()
}
jar.enabled=true
bootJar.enabled=false
运行结果及报错内容
Description:

Field testService in com.tianliang.app.controller.HelloController required a bean of type 'com.tianliang.service.service.TestService' that could not be found.


Action:

Consider defining a bean of type 'com.tianliang.service.service.TestService' in your configuration.

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • 您说的都对 2021-12-01 08:48
    关注

    gradle 6.7.1
    父级build.gradle

    
    plugins {
        id 'org.springframework.boot' version '2.0.2.RELEASE'
        id 'io.spring.dependency-management' version '1.0.11.RELEASE'
        id 'java'
    }
    
    // 构建配置
    ext {
        java_version = '1.8'
        spring_boot_version = '2.0.2.RELEASE'
        spring_gradle_plugin_version = '1.0.11.RELEASE'
    }
    
    //该项目与全部子项目的属性
    allprojects {
        group='com.tianliang'
        version='0.0.1-SNAPSHOT'
        //仓库,国内外仓库访问、下载速度会不同
        repositories {
            mavenLocal()
            maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
            mavenCentral()
        }
    }
    
    
    subprojects {
        apply plugin: 'org.springframework.boot'
        apply plugin: 'io.spring.dependency-management'
        apply plugin: 'java'
    
        sourceCompatibility = java_version
        targetCompatibility = java_version
    
        tasks.withType(JavaCompile) {
            options.encoding = 'UTF-8'
        }
    
        dependencies {
            implementation 'org.springframework.boot:spring-boot-starter-web'
            testImplementation 'org.springframework.boot:spring-boot-starter-test'
        }
    
        test {
            useJUnitPlatform()
        }
    
    }
    
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 12月8日
  • 创建了问题 11月30日