我尝试使用spring webmvc(版本4.1.6)和primefaces(版本5.2)启动我的新项目我能够启动项目,但是当尝试访问css或其他资源时该网址看起来像:http://localhost:8080/rais/public//javax.faces.resource/theme.css?ln=primefaces-aristo
,结果为404。部分:http://localhost:8080/rais/public/
看起来如预期。未找到弹簧mvc + Primefaces资源
我的配置:
@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);
}
WebMVC配置:
@Configuration
@EnableWebMvc
公共类WebMvcConfig延伸WebMvcConfigurerAdapter {
@Bean
ViewResolver viewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setViewClass(org.springframework.faces.mvc.JsfView.class);
resolver.setPrefix("/WEB-INF");
resolver.setSuffix(".xhtml");
return resolver;
}
faces-config.xml中(ANI在这个移动到Java暗示配置也非常感谢)
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
</application>
任何帮助,非常感谢。请询问是否需要附加信息:
为什么大家一直在试图将Spring MVC与JSF混合?是什么让Spring MVC变得如此特别,以至于它似乎必须与其完整的竞争对手JSF一起使用?还是每个Spring初学者将“Spring DI/IoC”与“Spring MVC”混淆/混合?仍然无法让我的头靠近它。 – BalusC
@BalusC:或者是Spring MVC,所以他们想要添加JSF ;-) – Kukeltje
@BalusC我建议在github上创建一些示例项目,以便人们可以从中学习。我很惊讶,primefaces没有例子“启动”项目......所以人们花在阅读随机博客和获取错误信息(显然)的时间花费在 – jNick