我希望将JavaServer Faces的支持添加到spring项目中,但是我在网上找到的教程教导说,要将其设置为项目,请将此行添加到文件 web.xml :
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
但是我的spring项目不使用XML文件进行配置,只使用java类。任何人都可以告诉我如何在这种情况下配置JavaServer Faces?
答案 0 :(得分:2)
基于等效类的配置将是:
public class MyInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
ServletRegistration.Dynamic facesServlet = servletContext.addServlet("Faces Servlet", new FacesServlet());
facesServlet.setLoadOnStartup(1);
facesServlet.addMapping("/faces/*");
}
}
更多详情here