There are loads of questions about spring boot not loading static resources and having read them all (almost) I still can't fix this issue. At this stage I have opted not to run with spring boot but I'd still like to know what the issue was. I am using Eclipse, Java 8 and Maven.
I have an application class that looks like this:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I have created a css file - src/main/resources/static/style.css
and referenced this from a jsp:
<link href="<c:url value='style.css'/>" rel="stylesheet">
The page loads but not the css. This is the error - 405 Method Not Allowed
I think think is correct but not sure. All help appreciated.
Based on some of the comments below this is how things look now.
My jsp files are configured in src/main/resources/application.properties as follows:
spring.mvc.view.prefix:/WEB-INF/views/
spring.mvc.view.suffix:.jsp
My Jsp is very simple, and is located in /WEB-INF/views/home.jsp
<!DOCTYPE html>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<link href="public/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<p>Hello world!</p>
</body>
</html>
I have also tried linking my css file like this:
<link href="style.css" rel="stylesheet" type="text/css"/>
My css file, located in webapp/public/style.css, is also very simple
p {
color: red;
}
My jsp loads but not the css. I have run my application using various methods including:
From the command line - java -jar contacts.jar
Inside eclipse - mvn spring-boot:run and mvn tomcat7:run-war Also inside eclipse by right clicking the Application.class file and selecting Run As -> Java Application.
I am using Spring Boot Version 1.4.0.RELEASE
jsp
files are configured? and you're sure you have no other static file configuration? – Entrepreneur