2015-05-04 103 views
1

我嘗試使用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> 

任何幫助,非常感謝。請詢問是否需要附加信息:

+1

爲什麼大家一直在試圖將Spring MVC與JSF混合?是什麼讓Spring MVC變得如此特別,以至於它似乎必須與其完整的競爭對手JSF一起使用?還是每個Spring初學者將「Spring DI/IoC」與「Spring MVC」混淆/混合?仍然無法讓我的頭靠近它。 – BalusC

+1

@BalusC:或者是Spring MVC,所以他們想要添加JSF ;-) – Kukeltje

+0

@BalusC我建議在github上創建一些示例項目,以便人們可以從中學習。我很驚訝,primefaces沒有例子「啓動」項目......所以人們花在閱讀隨機博客和獲取錯誤信息(顯然)的時間花費在 – jNick

回答

0

好吧,將UrlBasedViewResolver();更改爲InternalResourceViewResolver();現在它似乎正在工作。

+0

那麼您使用哪一類視圖類呢?如果我繼續使用這個: resolver.setViewClass(org.springframework.faces.mvc.JsfView.class); 然後它崩潰,因爲JsfView類與InternalResourceViewResolver不兼容 – Sloth