spring maven 搭建 springmvc

2021-03-01 07:28

阅读:602

标签:release   rtu   注入   gem   plugins   name   start   实例   encoding   

pom.xml

xml version="1.0" encoding="UTF-8"?>

project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  modelVersion>4.0.0modelVersion>

  groupId>com.chexdgroupId>
  artifactId>springmvcartifactId>
  version>1.0-SNAPSHOTversion>
  packaging>warpackaging>

  name>springmvc Maven Webappname>
  
  url>http://www.example.comurl>

  properties>
    project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    maven.compiler.source>1.7maven.compiler.source>
    maven.compiler.target>1.7maven.compiler.target>
  properties>
  dependencies>
    dependency>
      groupId>junitgroupId>
      artifactId>junitartifactId>
      version>4.12version>
    dependency>
    dependency>
      groupId>org.springframeworkgroupId>
      artifactId>spring-webmvcartifactId>
      version>5.1.9.RELEASEversion>
    dependency>
    dependency>
      groupId>javax.servletgroupId>
      artifactId>javax.servlet-apiartifactId>
      version>4.0.1version>
      scope>providedscope>
    dependency>
    dependency>
      groupId>javax.servletgroupId>
      artifactId>servlet-apiartifactId>
      version>2.5version>
    dependency>
    dependency>
      groupId>javax.servlet.jspgroupId>
      artifactId>jsp-apiartifactId>
      version>2.2version>
    dependency>
    dependency>
      groupId>javax.servletgroupId>
      artifactId>jstlartifactId>
      version>1.2version>
    dependency>
    dependency>
      groupId>javax.servletgroupId>
      artifactId>servlet-apiartifactId>
      version>2.5version>
    dependency>
    dependency>
      groupId>javax.servlet.jspgroupId>
      artifactId>jsp-apiartifactId>
      version>2.2version>
    dependency>
  dependencies>

  build>
    finalName>springmvcfinalName>
    pluginManagement>
      plugins>
        plugin>
          artifactId>maven-clean-pluginartifactId>
          version>3.1.0version>
        plugin>
        
        plugin>
          artifactId>maven-resources-pluginartifactId>
          version>3.0.2version>
        plugin>
        plugin>
          artifactId>maven-compiler-pluginartifactId>
          version>3.8.0version>
        plugin>
        plugin>
          artifactId>maven-surefire-pluginartifactId>
          version>2.22.1version>
        plugin>
        plugin>
          artifactId>maven-war-pluginartifactId>
          version>3.2.2version>
        plugin>
        plugin>
          artifactId>maven-install-pluginartifactId>
          version>2.5.2version>
        plugin>
        plugin>
          artifactId>maven-deploy-pluginartifactId>
          version>2.8.2version>
        plugin>
      plugins>
    pluginManagement>
  build>
project>

web.xml

xml version="1.0" encoding="UTF-8"?>
web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

  
  servlet>
    servlet-name>springmvcservlet-name>
    servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    
    init-param>
      param-name>contextConfigLocationparam-name>
      param-value>classpath:springmvc-servlet.xmlparam-value>
    init-param>
    
    load-on-startup>1load-on-startup>
  servlet>

  
  
  servlet-mapping>
    servlet-name>springmvcservlet-name>
    url-pattern>/url-pattern>
  servlet-mapping>
  filter>
    filter-name>encodingfilter-name>
    filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    init-param>
      param-name>encodingparam-name>
      param-value>utf-8param-value>
    init-param>
  filter>
  filter-mapping>
    filter-name>encodingfilter-name>
    url-pattern>/*url-pattern>
  filter-mapping>
web-app>

springmvc-servlet.xml

xml version="1.0" encoding="UTF-8"?>
beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    
    context:component-scan base-package="com.chexd"/>
    
    mvc:default-servlet-handler />
    
    mvc:annotation-driven />

    
    bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          id="internalResourceViewResolver">
        
        property name="prefix" value="/WEB-INF/jsp/" />
        
        property name="suffix" value=".jsp" />
    bean>
beans>

 

spring maven 搭建 springmvc

标签:release   rtu   注入   gem   plugins   name   start   实例   encoding   

原文地址:https://www.cnblogs.com/chengfengchi/p/14449121.html


评论


亲,登录后才可以留言!