Java 春季MVC赢得';t加载静态内容
我是Spring新手,我想在视图中加载一些css和js 静态内容现在位于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
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";
}
}