0%

spring boot in action 1

重新认识spring

基于servlet 的web开发

首先我们会定义

如果开发一个简单的 hello world web应用

  • 一个项目结构

  • 一个web.xml 文件 或者WebApplicationInitializer实现.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <?xml version="1.0"encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/controllers.xml,/WEB-INF/service.xml</param-value>
    </context-param>
    <servlet>
    <servlet-name>dispatch</servlet>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>dispatch</servlet-name>
    <servlet-pattern>*.*</servlet-pattern>
    </servlet-mapping>
    </web-app>