Currently, I am working on a Spring MVC application in Eclipse with Jetty. I have opted for using annotations instead of a web.xml file. Despite trying various solutions found online, I am still unable to get my CSS to work.
The location of my CSS file is as follows:
src/main/webapp/resources/css/main.css
In my JSP file, I have added the following line:
<link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/main.css" />">
This line appears to be correct and resolves to:
<link rel="stylesheet" type="text/css" href="/resources/css/main.css">
I attempted adding the following code to my applicationContext.xml:
<mvc:resources mapping="/resources/**" location="/resources/" />
However, the CSS file still cannot be found.
Any suggestions would be greatly appreciated.
EDIT
Below is my initializer code:
public class WebInitializer implements WebApplicationInitializer {
private final Logger log = Logger.getLogger(WebInitializer.class);
public void onStartup(ServletContext container) {
log.info("Starting web app");
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(AppConfig.class);
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(MvcConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}