02-知识记录
一.SpringBoot 的钩子函数
1.CommandLineRunner 和 ApplicationRunner springboot 在启动后会在容器里取这两个接口的实例,调用其中的run方法
参考博客: https://blog.csdn.net/xuanmobaobao/article/details/89015608
2.BeanFactoryPostProcessor 和 BeanPostProcessor
参考博客 BeanPostProcessor:https://www.jianshu.com/p/8e2d400492c7
二.Spring 中的监听器
三.Spring 中的过滤器
四.Spring 中的拦截器
五.Spring 中的前端控制器(DispatcherServlet)
六.SSM(Spring SpringMVC Mybatis) 的 web项目中的最基本的配置
1.Tomcat启动时会加载WEB-INF/web.xml文件,所以SSM 的项目还需要在WEB-INF/web.xml中配置
一般包括以下几项: 全局参数(context-param)、 监听器(listener)、 过滤器(filter)、 前端控制器(DispatcherServlet)
全局参数:指定配置文件的路径
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/*.xml,classpath:spring-security.xml</param-value>
</context-param>
<!--监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!--编码过滤器-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--前端控制器-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2.然后根据前端控制器中配置的contextConfigLocation指定的配置文件,来配置前端控制器相关配置
前端控制器配置一般包括以下几项:
处理器映射器(HandlerMapping)
处理器适配器(HandlerAdapter)
视图解析器(ViewReslover)
1).处理器映射器 和 处理器适配器 的配置有2种:
1.一种是xml中用 bean 标签配置
2.一种是配置注解驱动器<mvc:annotation-driven/>
xml中用bean标签配置(不推荐)
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
备注:
这种方式配置不能使用@Controller注解,需要手动实现org.springframework.web.servlet.mvc.Controller接口,
然后在配置文件中在配置(Handler)每个实现类
配置注解驱动器
<mvc:annotation-driven/>
<context:component-scan base-package=""/>
备注:
1.<mvc:annotation-driven/>的作用就相当于xml 中的bean的配置的
RequestMappingHandlerMapping 和 RequestMappingHandlerAdapter
2.<mvc:annotation-driven/> 要和 <context:component-scan base-package=""/> 配合使用,
这样spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有
@Component @Controller@Service等这些注解的类,则把这些类注册为bean
2). 配置视图解析器:(如果是前后端分离的项目,视图解析器应该可以省略)
参考博客:https://blog.csdn.net/py941215/article/details/78302408
七.SpringBoot 项目中的MVC的配置
SpringBoot 项目中通过自动装配等技术,简化了WebMvc的配置
参考博客:从Spring到SpringBoot构建WEB MVC核心配置详解 https://www.cnblogs.com/jimisun/p/10084461.html
八.Java web 应用中安全框架使用率高的莫过于:
spring-security:https://spring.io/projects/spring-security
spring-security使用参考博客:https://blog.csdn.net/wangmx1993328/article/details/88867153
Apache Shiro :http://shiro.apache.org/
Last updated
Was this helpful?