【问题标题】:Spring Boot Tutorial doesn't work with multi project gradle setupSpring Boot 教程不适用于多项目 gradle 设置
【发布时间】:2015-10-15 09:35:19
【问题描述】:

当我从位于https://spring.io/guides/gs/serving-web-content/ 的 gradle 文件切换到多项目 gradle 文件设置时,我得到了一个奇怪的行为(至少对我来说:D)。

根目录下的build.gradle

//Applied to all projects.
allprojects {
    apply plugin: 'eclipse'
    apply plugin: 'idea'


    group = 'de.test.platform'
    version = '0.1'
}

subprojects {

    //Currently all subprojects are also java projects. If this changes we
    //need to move it into the corresponding projects
    apply plugin: 'java'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        mavenLocal()
        mavenCentral()
    }

    idea {
        module {
            downloadSources = true
            downloadJavadoc = false
        }
    }
}

idea {
    project {
        jdkName = '1.8'
        languageLevel = '1.8'
    }
}

子目录frontend中的build.gradle(因此子项目称为:frontend)

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

apply plugin: 'war'
apply plugin: 'spring-boot'

jar {
    baseName = 'crowdio-frontend'
    version = '0.1.0'
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("junit:junit")
}

当我在教程中运行 gradle bootRun 并导航到 http://localhost:8080/greeting 时,我得到一个无限循环错误。如果我将模板从 greeting.html 更改为 hello.html 并在控制器 greeting() 操作中返回 hello 而不是 greeting,我会收到 404 错误。

模板存放在project_root/frontend/src/main/resources/templates/greeting.html

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    似乎无论出于何种原因,spring boot 都可以使用教程中的 gradle 构建文件的确切结构来决定 thymeleaf。但是,如果您切换到多项目设置,则需要添加

    compile("org.thymeleaf:thymeleaf-spring4")
    

    作为依赖。

    【讨论】:

      猜你喜欢
      • 2015-06-28
      • 2021-04-06
      • 1970-01-01
      • 2014-07-27
      • 2019-03-02
      • 2020-05-25
      • 2018-08-25
      • 2020-04-13
      • 1970-01-01
      相关资源
      最近更新 更多