【发布时间】:2014-02-23 10:16:41
【问题描述】:
我有一个 Spring MVC 应用程序,我正在尝试使用 eclipse 和 jetty 运行。所有注释,没有 web.xml。在这里尝试了一半的答案后,我仍然无法让我的 CSS 工作。
我的 CSS 在这里
src/main/webapp/resources/css/main.css
在我的 JSP 中有
<link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/main.css" />">
看起来正确,解析为
<link rel="stylesheet" type="text/css" href="/resources/css/main.css">
我尝试将它添加到我的 applicationContext.xml
<mvc:resources mapping="/resources/**" location="/resources/" />
它仍然没有找到 css。
有什么想法吗?
编辑
我的初始化器
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("/");
}
}
【问题讨论】:
-
浏览器的开发工具是怎么说的?
-
您的
DispatcherServlet是如何映射的? -
@M. Deinum,查看我的编辑,添加了我的初始化程序。
-
将
<mvc:default-servlet-handler />添加到您的配置中。 -
不走运。仍然得到 404。
标签: css eclipse spring model-view-controller jetty