Yooouuri Yooouuri - 1 year ago 108
CSS Question

Spring MVC won't load static content

I am new to Spring and i want to load some css and js into a view.

The static content is now in

but when i navigate to
it gives me a 404 error..

I don't use any xml configuration files.

My project structure:

project structure

Update: Application class

package com.exstodigital.photofactory;

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

public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);

Update: build.gradle

buildscript {
repositories {
dependencies {

group 'PTS4'
version '1.0-SNAPSHOT'

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

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {

dependencies {

Some controller (just testing stuff):

package com.exstodigital.photofactory;

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

public class MainController {

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

return name;

public String test() {
return "test";

Answer Source

Your structure is correct. Don't forget to make gradle clean task before run bootRun.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download