Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 为什么intellij运行SpringBootApplication很好,而打包jar找不到资源?_Spring Boot - Fatal编程技术网

Spring boot 为什么intellij运行SpringBootApplication很好,而打包jar找不到资源?

Spring boot 为什么intellij运行SpringBootApplication很好,而打包jar找不到资源?,spring-boot,Spring Boot,我有一个使用Springboot/gradle/java的简单POST表单。我不明白的是,为什么当我右键单击并点击RunfromIntelliJ时,应用程序会发现索引页,没有问题。但是当我将其打包为jar时,它将找不到索引页。我可以手动输入,但是当我在写文章的时候会遇到奇怪的问题,所以我要先解决第一个问题 这是我的主要观点: import org.springframework.boot.SpringApplication import org.springframework.boot.auto

我有一个使用Springboot/gradle/java的简单POST表单。我不明白的是,为什么当我右键单击并点击RunfromIntelliJ时,应用程序会发现索引页,没有问题。但是当我将其打包为jar时,它将找不到索引页。我可以手动输入,但是当我在写文章的时候会遇到奇怪的问题,所以我要先解决第一个问题

这是我的主要观点:

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class HandlingRewardsFormSubmission{
    static void main(String[] args) {
        SpringApplication.run(HandlingRewardsFormSubmission.class, args)
    }
}

我的控制器

import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PostMapping

@Controller
class RewardsDataController {
    @GetMapping("/")
    String index(Model model){
        return "index"
    }
目录结构

src
-main
-resources
-application.properties
--META-INF
---MANIFEST.MF
--templates
---index.html
由于此错误消息,我尝试在(/、resources/、resources/和resources/templates/等)周围移动web资源目录,但没有任何效果,但我质疑,当我根据

哦,还有我的gradle档案:

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'war'
    id 'groovy'
//    id 'java'
}
war {
    enabled = true
}
jar {
    manifest {
        attributes 'Main-Class': 'co.za.ebucks.HandlingRewardsFormSubmission'
    }
}
group = 'co.za.ebucks'
version = '1.0.0'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}
ext {
    seleniumVersion = '3.141.59'
}
configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}
test {
    useTestNG()
}

dependencies {
//    compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
    implementation 'org.springframework.boot:spring-boot-starter-tomcat'
    compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '9.0.31'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.session:spring-session-core'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

    implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0'
    implementation group: 'com.google.inject', name: 'guice', version: '4.2.2'
    implementation group: 'com.google.guava', name: 'guava', version: '28.1-jre'
    implementation group: 'cglib', name: 'cglib', version: '3.3.0'
    implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.10'

    testImplementation group: 'org.testng', name: 'testng', version: '7.1.0'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation "org.seleniumhq.selenium:selenium-support:${seleniumVersion}"
    testImplementation group: 'io.appium', name: 'java-client', version: '7.3.0'
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: "${seleniumVersion}"
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-server', version: "${seleniumVersion}"
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: "${seleniumVersion}"
    testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0'
    testImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0'


    developmentOnly 'org.springframework.boot:spring-boot-devtools'


}

我现在觉得自己太傻了。请原谅,这是我第一次使用spring,也是我15年来第一次建立网站

问题不在于上述内容,而在于如何配置web方面的资源。“src/main/resources/”目录应该是web资源目录的根路径“/”。对我来说,这不是最明显的事情:(

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'war'
    id 'groovy'
//    id 'java'
}
war {
    enabled = true
}
jar {
    manifest {
        attributes 'Main-Class': 'co.za.ebucks.HandlingRewardsFormSubmission'
    }
}
group = 'co.za.ebucks'
version = '1.0.0'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}
ext {
    seleniumVersion = '3.141.59'
}
configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}
test {
    useTestNG()
}

dependencies {
//    compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
    implementation 'org.springframework.boot:spring-boot-starter-tomcat'
    compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '9.0.31'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.session:spring-session-core'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

    implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0'
    implementation group: 'com.google.inject', name: 'guice', version: '4.2.2'
    implementation group: 'com.google.guava', name: 'guava', version: '28.1-jre'
    implementation group: 'cglib', name: 'cglib', version: '3.3.0'
    implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.10'

    testImplementation group: 'org.testng', name: 'testng', version: '7.1.0'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation "org.seleniumhq.selenium:selenium-support:${seleniumVersion}"
    testImplementation group: 'io.appium', name: 'java-client', version: '7.3.0'
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: "${seleniumVersion}"
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-server', version: "${seleniumVersion}"
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: "${seleniumVersion}"
    testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0'
    testImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0'


    developmentOnly 'org.springframework.boot:spring-boot-devtools'


}