我正在尝试使用带有primefaces(版本5.2)的spring webmvc(版本4.1.6)启动我的新项目。我可以启动项目,但是当尝试访问css或其他资源时,url看起来像:{{ 1}}并生成404.部分:http://localhost:8080/rais/public//javax.faces.resource/theme.css?ln=primefaces-aristo
看起来像预期的那样。
我的配置:
http://localhost:8080/rais/public/
WebMVC配置:
@Configuration
@EnableTransactionManagement
@EnableSpringConfigured
@EnableWebMvc
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
//Set init params
// Use JSF view templates saved as *.xhtml, for use with Facelets
servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
servletContext.setInitParameter("javax.faces.FACELETS_VIEW_MAPPINGS", "*.xhtml");
ServletRegistration.Dynamic facesServlet = servletContext.addServlet("Faces Servlet", javax.faces.webapp.FacesServlet.class);
facesServlet.setLoadOnStartup(1);
facesServlet.addMapping("*.xhtml");
ServletRegistration.Dynamic registration = servletContext.addServlet("dsp", new DispatcherServlet());
registration.setInitParameter("contextConfigLocation", "");
registration.setLoadOnStartup(1);
registration.addMapping("/");
servletContext.addListener(ConfigureListener.class);
servletContext.addListener(org.springframework.web.context.request.RequestContextListener.class);
//Add OpenEntityManagerInViewFilter Filter
servletContext.addFilter("openEntityManagerInViewFilter", OpenEntityManagerInViewFilter.class).addMappingForUrlPatterns(null, true, "/*");
super.onStartup(servletContext);
}
public class WebMvcConfig扩展了WebMvcConfigurerAdapter {
@Configuration
@EnableWebMvc
faces-config.xml(ani暗示将此移动到java配置也非常感谢)
@Bean
ViewResolver viewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setViewClass(org.springframework.faces.mvc.JsfView.class);
resolver.setPrefix("/WEB-INF");
resolver.setSuffix(".xhtml");
return resolver;
}
非常感谢任何帮助。请询问是否需要其他信息:
答案 0 :(得分:0)
好的,将UrlBasedViewResolver();
更改为InternalResourceViewResolver();
,现在它似乎正在运作。