Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.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
Java 春季MVC赢得';t加载静态内容_Java_Css_Spring_Spring Mvc_Static Content - Fatal编程技术网

Java 春季MVC赢得';t加载静态内容

Java 春季MVC赢得';t加载静态内容,java,css,spring,spring-mvc,static-content,Java,Css,Spring,Spring Mvc,Static Content,我是Spring新手,我想在视图中加载一些css和js 静态内容现在位于src/main/resources/static/…中,但当我导航到localhost:8080/css/test.css时,会出现404错误 我不使用任何xml配置文件 我的项目结构: 更新:应用程序类 package com.exstodigital.photofactory; import org.springframework.boot.SpringApplication; import org.springf

我是Spring新手,我想在视图中加载一些css和js

静态内容现在位于
src/main/resources/static/…
中,但当我导航到
localhost:8080/css/test.css
时,会出现404错误

我不使用任何xml配置文件

我的项目结构:

更新:应用程序类

package com.exstodigital.photofactory;

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

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
更新:build.gradle

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

group 'PTS4'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-devtools")
    testCompile("junit:junit")
}
一些控制器(只是测试东西):


你的结构是正确的。在运行
bootRun
之前,不要忘记将gradle
任务清理干净

你能在这里发布你的
build.gradle
和你的控制器代码吗?也许您有一些覆盖默认值的依赖项settings@jahra添加了build.gradle和controllerI,我复制了您的所有代码,它可以正常工作。所以我不知道怎么帮你anymore@jahra您可以查看test.css吗?
package com.exstodigital.photofactory;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
//@Controller
public class MainController {

    //@ResponseBody
    @RequestMapping("/greeting/{name}/{hoi}")
    public String greeting(@PathVariable("name") String name, @PathVariable("hoi") String hoi) {
        //model.addAttribute("message", "BERICHT");

        return name;
    }

    @RequestMapping("/test")
    public String test() {
        return "test";
    }
}