我有一个非常简单的web.xml的webapp。春季无法在webapp中提供静态文件
<?xml version="1.0"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
</web-app>
我设置的contextConfigLocation属性,使类org.glassfish.jersey.server.spring.SpringWebApplicationInitializer我想手动执行此操作不会自动添加ContextLoadListener和RequestContextListener。
然后我有我自己的WebApplicationInitializer类以编程方式添加servlet而不是通过web.xml。
public class MyWebAppInitializer implements WebApplicationInitializer {
private static final Logger LOGGER = Logger.getLogger(SpringWebApplicationInitializer.class.getName());
@Override
public void onStartup(ServletContext sc) throws ServletException {
//Setup spring listeners
{
LOGGER.config(LocalizationMessages.REGISTERING_CTX_LOADER_LISTENER());
sc.addListener(ContextLoaderListener.class);
sc.addListener(RequestContextListener.class);
}
//Jersey Rest Servlet
{
final ServletRegistration.Dynamic registration = sc.addServlet(ServletContainer.class.getName(), ServletContainer.class);
registration.setInitParameter("javax.ws.rs.Application", com.tervita.portal.RestApplication.class.getName());
registration.addMapping("/rest/*");
}
//Normal Servlets
{
final ServletRegistration.Dynamic registration = sc.addServlet(LoginAction.class.getName(), LoginAction.class);
registration.addMapping("/LoginAction");
}
//Apache Default Servlet
{
ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher", DispatcherServlet.class);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/test");
}
}
}
当我跑我的web应用程序,我无法访问我已经加入诸如/css/app/ui-grid.css静态文件。
当我运行Tomcat我得到这个虽然...
所以我很困惑,我没有在我的servlet配置覆盖默认的servlet的任何条目这Tomcat应该是/ *。为什么默认的servlet不会被击中并提供我的内容?
在tomcat管理控制台中,你能看到你的web应用程序被部署到的上下文(路径)吗?也许它被部署到根上下文('/')而不是'/ tervita360'? – ochi
是的,它绝对是在/ tervita360。此外我的测试servlet是可达的。 – benstpierre
你的WAR文件的内容怎么样?他们是否正确?你看过WAR文件来确认所有必要的文件在那里吗? - 现在只包括基础知识 – ochi