下面列出了org.springframework.boot.web.servlet.ServletRegistrationBean#setUrlMappings ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* This bean registers the {@link FacesServlet}.
* <p>
* This {@link ServletRegistrationBean} also sets two
* {@link ServletContext#setAttribute(String, Object) servlet-context attributes} to inform Mojarra and MyFaces about
* the dynamically added Servlet.
*
* @param facesServletProperties The properties for the {@link FacesServlet}-registration.
*
* @return A custom {@link ServletRegistrationBean} which registers the {@link FacesServlet}.
*/
@Bean
public ServletRegistrationBean<FacesServlet> facesServletRegistrationBean(
FacesServletProperties facesServletProperties
) {
ServletRegistrationBean<FacesServlet> facesServletServletRegistrationBean = new ServletRegistrationBean<FacesServlet>(new FacesServlet()) {
@Override
protected ServletRegistration.Dynamic addRegistration(String description, ServletContext servletContext) {
ServletRegistration.Dynamic servletRegistration = super.addRegistration(description, servletContext);
if (servletRegistration != null) {
servletContext.setAttribute("org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET", true);
servletContext.setAttribute("com.sun.faces.facesInitializerMappingsAdded", true);
}
return servletRegistration;
}
};
facesServletServletRegistrationBean.setName(facesServletProperties.getName());
facesServletServletRegistrationBean.setUrlMappings(facesServletProperties.getUrlMappings());
facesServletServletRegistrationBean.setLoadOnStartup(facesServletProperties.getLoadOnStartup());
facesServletServletRegistrationBean.setEnabled(facesServletProperties.isEnabled());
facesServletServletRegistrationBean.setAsyncSupported(facesServletProperties.isAsyncSupported());
facesServletServletRegistrationBean.setOrder(facesServletProperties.getOrder());
return facesServletServletRegistrationBean;
}
@Bean
public ServletRegistrationBean<Monitor> monitor() {
ServletRegistrationBean<Monitor> srb = new ServletRegistrationBean<>();
srb.setServlet(new Monitor());
srb.setUrlMappings(Collections.singletonList("/ok"));
return srb;
}
/**
* Druid的servlet
*
* @return
*/
@Bean
public ServletRegistrationBean statViewServlet() {
ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet());
Map<String, String> initParams = new HashMap<>();
initParams.put("loginUsername", "root");
initParams.put("loginPassword", "root");
initParams.put("allow", "127.0.0.1");
bean.setInitParameters(initParams);
bean.setUrlMappings(Arrays.asList("/druid/*"));
return bean;
}
@Bean
ServletRegistrationBean JavametricsCodewindSpringServletRegistration () {
ServletRegistrationBean srb = new ServletRegistrationBean();
srb.setServlet(new WebPage());
srb.setUrlMappings(Arrays.asList("/metrics/codewind"));
return srb;
}