您的位置:首页 > 编程语言 > Java开发

013-Spring Boot web【二】静态资源、Servlet、Filter、listenter

2018-02-06 22:18 465 查看

一、静态资源

1.1、webapp默认支持静态资源

在src/main/webapp下建立user.html默认支持访问

1.2、默认内置静态资源目录。可被直接访问

查看包:spring-boot-autoconfigure-1.5.9.RELEASE.jar下的:org.springframework.boot.autoconfigure.web;

查看:ResourceProperties,其中

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };


默认放在以上四个目录均可被访问。

可以通过修改配置项,在src/main/resources下的application.properties中

spring.resources.staticLocations=classpath:/html/


二、spring boot中使用Servlet【原始】以来Servlet3.x注解功能

2.1、使用Servlet

新建一个UserServlet.java

@Bean
public ServletListenerRegistrationBean<StartupListener> createServletListenerRegistrationBean() {
ServletListenerRegistrationBean<StartupListener> registrationBean = new ServletListenerRegistrationBean<StartupListener>(new StartupListener());
return registrationBean;
}


View Code
注:一般使用2中注解,因为Spring boot基于spring 4.x ,spring 4.x 开发的web一般使用Servlet3.x以上
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: