从springmvc 过度到 springboot

1、web.xml 形式的MVC项目

web.xml ,web.xml的启动类在 web 容器里,即Tomcat中。

Tomcat的main方法会加载 web.xml。为什么Tomcat会加载 web.xml 这是,java的要求,如果要成为java的web容器就必须实现这个功能。这就是问什么 nginx 不能做 web容器。

<listener> 
   <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> 
</listener>
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/applicationContext-*.xml
            classpath*:/applicationContext.xml
        </param-value>
    </context-param>

applicationContent.xml :名字自定义的,和 <context-param> 里的对应上就好。而且可以不止这两个xml,可以有很多。

扫描业务包

<context:component-scan base-package="com.wsights" ></context:component-scan>

springmvc.xml:名字自定义的

扫描controller

<context:component-scan base-package="com.wsights.*.*.controller" />
为什么这两个扫描要放在两个文件下,因为 spring2.X 时,放在一起会导致事物失效。

2、无 xml 的web项目

WebApplicationInitializer

3、springboot如何做到内嵌Tomcat的

4、spring实现无 xml 配置的条件

spring有了 java config

Tomcat实现了 serverlet ,所以才能做 java的web容器

serverlet3.1 有了新规范  org.springframework.web.SpringServletContainerInitializer 。Tomcat8 支持 serverlet 的新规范。

5、spring framework:spring框架包含的内容可以看官网的 projects。其中springmvc 只是 spring framework 的一个知识点。

原文地址:https://www.cnblogs.com/cuiqq/p/11846918.html