<servlet>
<servlet-name>restServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring2.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ModelRestServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
@Bean
public ServletRegistrationBean restServlet(){
//注解扫描上下文
AnnotationConfigWebApplicationContext applicationContext
= new AnnotationConfigWebApplicationContext();
//base package
applicationContext.scan("com.jerryl.rest");
//通过构造函数指定dispatcherServlet的上下文
DispatcherServlet rest_dispatcherServlet
= new DispatcherServlet(applicationContext);
//用ServletRegistrationBean包装servlet
ServletRegistrationBean registrationBean
= new ServletRegistrationBean(rest_dispatcherServlet);
registrationBean.setLoadOnStartup(1);
//指定urlmapping
registrationBean.addUrlMappings("/rest/*");
//指定name,如果不指定默认为dispatcherServlet
registrationBean.setName("rest");
return registrationBean;
}
public ServletRegistrationBean dispatcherServletRegistration(DispatcherServlet dispatcherServlet) {
ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet, new String[]{this.serverProperties.getServletMapping()});
registration.setName("dispatcherServlet");
registration.setLoadOnStartup(this.webMvcProperties.getServlet().getLoadOnStartup());
if(this.multipartConfig != null) {
registration.setMultipartConfig(this.multipartConfig);
}
return registration;
}
}
@Configuration
@ComponentScan("org.activiti.rest.service.api")
@EnableWebMvc
public class Cfg_Rest {
···
}
mvc: #默认为/** static-path-pattern: /** resources: #默认为classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ 。配置多个路径,中间用逗号隔开。 static-locations:
@Configuration
@EnableWebMvc
public class Cfg_View extends WebMvcConfigurerAdapter{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有