zoukankan      html  css  js  c++  java
  • SSM整合及Maven pom.xml

    1.   web.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
     3   <display-name>pms</display-name>
     4   <welcome-file-list>
     5     <welcome-file>login.jsp</welcome-file>
     6   </welcome-file-list>
     7 
     8   <!-- Spring -->
     9   <context-param>
    10     <param-name>contextConfigLocation</param-name>
    11     <param-value>classpath:beans.xml</param-value>
    12   </context-param>
    13 
    14   <!-- Spring上下文监视器 -->
    15   <listener>
    16     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    17   </listener>
    18 
    19 
    20   <!-- SpringMVC -->
    21   <servlet>
    22     <servlet-name>springDispatcherServlet</servlet-name>
    23     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    24     <init-param>
    25       <param-name>contextConfigLocation</param-name>
    26       <param-value>classpath:springmvc.xml</param-value>
    27     </init-param>
    28     <load-on-startup>1</load-on-startup>
    29   </servlet>
    30   
    31   <servlet-mapping>
    32     <servlet-name>springDispatcherServlet</servlet-name>
    33     <url-pattern>/</url-pattern>
    34   </servlet-mapping>
    35 
    36   <!-- 两个filter -->
    37   <filter>
    38     <filter-name>characterEncodingFilter</filter-name>
    39     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    40     <init-param>
    41       <param-name>encoding</param-name>
    42       <param-value>UTF-8</param-value>
    43     </init-param>
    44   </filter>
    45 
    46   <filter-mapping>
    47     <filter-name>characterEncodingFilter</filter-name>
    48     <url-pattern>/*</url-pattern>
    49   </filter-mapping>
    50   <filter>
    51     <filter-name>hiddenHttpMethodFilter</filter-name>
    52     <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    53   </filter>
    54   <filter-mapping>
    55     <filter-name>hiddenHttpMethodFilter</filter-name>
    56     <url-pattern>/*</url-pattern>
    57   </filter-mapping>
    58 
    59 </web-app>

    2.Spring配置文件beans.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    
        <context:component-scan base-package="com.skk">
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
            <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
        </context:component-scan>
    
        <aop:aspectj-autoproxy/>
    
        <!--数据源与数据源事务管理器-->
        <context:property-placeholder location="classpath:jdbc.properties"/>
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
            <property name="driverClassName" value="${jdbc.driverClass}"></property>
            <property name="url" value="${jdbc.jdbcUrl}"></property>
            <property name="username" value="${jdbc.userName}"></property>
            <property name="password" value="${jdbc.password}"></property>
        </bean>
    
        <bean name="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
        </bean>
    
        <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/>
    
        <!--MyBatis 相关-->
        <bean class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="classpath:mybatis-spring.xml"/>
        </bean>
    
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.skk"></property>
        </bean>
    
    </beans>

    3.SpringMVC全局配置文件 springmvc.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:aop="http://www.springframework.org/schema/aop" 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 http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <!-- 配置扫描包 -->
        <context:component-scan base-package="com.skk" use-default-filters="false">
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
            <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
        </context:component-scan>
    
        <aop:aspectj-autoproxy/>
    
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
        <!--全局类型转换器-->
        <bean id="converter" class="com.skk.utils.DataTimeConvert"></bean>
        <bean id="conversionServiceFactoryBean" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
            <property name="converters">
                <set>
                    <ref bean="converter"></ref>
                </set>
            </property>
        </bean>
    
        <!--上传与下载-->
        <bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver">
            <property name="defaultEncoding" value="UTF-8"></property>
            <property name="maxUploadSize" value="#{50*1024*1024}"></property>
        </bean>
    
        <mvc:default-servlet-handler/>
        <mvc:annotation-driven conversion-service="conversionServiceFactoryBean"/>
    
    </beans>

    4.Spring整合MyBatis spring-mybatis.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-config.dtd">
    
    <configuration>
    
        <!--此处用于书写设置代码-->
        <settings>
            <setting name="" value=""/>
        </settings>
    
        <!--插件位置-->
        <plugins>

        <!-- <plugin interceptor="com.github.pagehelper.PageInterceptor"> <property name="helperDialect" value="mysql"></property> </plugin>
        -->
    </plugins> </configuration>

    5.Maven的基础依赖(SSM)

    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.0</modelVersion>
    
      <groupId>com.skk</groupId>
      <artifactId>pms</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>war</packaging>
    
      <name>Maven Webapp</name>
      <!-- FIXME change it to the project's website -->
      <url>http://www.example.com</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
    
      <dependencies>
        <!-- spring的jar包 -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-expression</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aspects</artifactId>
          <version>4.0.0.RELEASE</version>
          <exclusions>
            <exclusion>
              <groupId>org.aspectj</groupId>
              <artifactId>aspectjweaver</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <!-- mysql -->
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.37</version>
        </dependency>
        <!-- druid -->
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.1.10</version>
        </dependency>
    
    
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.9</version>
        </dependency>
        <!-- aop AND Transaction -->
        <dependency>
          <groupId>net.sourceforge.cglib</groupId>
          <artifactId>com.springsource.net.sf.cglib</artifactId>
          <version>2.2.0</version>
        </dependency>
    
        <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>1.6.8</version>
        </dependency>
    
    
        <!-- JDBCTemplate and Transaction -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-orm</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
        <!-- springmvc -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>4.0.0.RELEASE</version>
        </dependency>
        <!-- upload -->
        <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.3.1</version>
        </dependency>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
        </dependency>
    
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>3.4.1</version>
        </dependency>
    
        <!-- mybatis逆向工程 -->
        <dependency>
          <groupId>org.mybatis.generator</groupId>
          <artifactId>mybatis-generator-core</artifactId>
          <version>1.3.2</version>
        </dependency>
        <!-- 整合spring和mybatis -->
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>1.3.0</version>
        </dependency>
    
        <!-- JSTL  -->
        <dependency>
          <groupId>org.apache.taglibs</groupId>
          <artifactId>taglibs-standard-impl</artifactId>
          <version>1.2.1</version>
        </dependency>
        <dependency>
          <groupId>org.apache.taglibs</groupId>
          <artifactId>taglibs-standard-spec</artifactId>
          <version>1.2.1</version>
        </dependency>
    
    
        <!--JSON -->
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-annotations</artifactId>
          <version>2.1.5</version>
        </dependency>
    
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
          <version>2.1.5</version>
        </dependency>
    
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
          <version>2.1.5</version>
        </dependency>
    
    
    
        <!-- jsp-servlet -->
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
          <version>2.5</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.0</version>
          <scope>provided</scope>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
          <version>1.1.3</version>
        </dependency>
    
    
        <dependency>
          <groupId>redis.clients</groupId>
          <artifactId>jedis</artifactId>
          <version>2.9.0</version>
        </dependency>
    
        <dependency>
          <groupId>org.springframework.data</groupId>
          <artifactId>spring-data-redis</artifactId>
          <version>1.6.0.RELEASE</version>
        </dependency>
    
        <!--分页-->
        <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper</artifactId>
          <version>5.1.10</version>
        </dependency>
          <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.10</version>
          </dependency>
    
          <!--谷歌kapatcha验证码工具-->
    <!--    <dependency>
          <groupId>com.github.penggle</groupId>
          <artifactId>kaptcha</artifactId>
          <version>2.3.2</version>
        </dependency>-->
        <!--发送Email 所需类库包 -->
    <!--    <dependency>
          <groupId>javax.mail</groupId>
          <artifactId>mail</artifactId>
          <version>1.4.7</version>
        </dependency>-->
    
    
      </dependencies>
    
      <build>
    
        <plugins>
          <!--tomcat7 插件-->
          <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
              <path>/pms</path>
              <port>8080</port>
              <uriEncoding>UTF-8</uriEncoding>
            </configuration>
          </plugin>
    
          <!--MyBatis 逆向工程插件-->
          <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>
            <dependencies>
              <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.8</version>
              </dependency>
            </dependencies>
            <configuration>
              <!--配置文件的路径-->
              <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
              <overwrite>true</overwrite>
            </configuration>
          </plugin>
    
    
    
        </plugins>
    
        <resources>
          <resource>
            <directory>src/main/java</directory>
            <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
          </resource>
          <resource>
            <directory>src/main/resources</directory>
            <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
          </resource>
        </resources>
      </build>
    
    </project>
    pom.xml

     注意!!!

    pom.xml文件中的依赖版本可能不符合所有开发需求,此处只做演示用处

    可以自行更改版本信息

  • 相关阅读:
    C#怎样保证弹出窗体是唯一并居中显示
    1、怎样设置C#OpenFileDialog(文件选择窗体)的指定路径、文件格式等属性(设置打开默认路径、文件格式、窗体显示文本)
    FTP在CentOS上安装与使用
    nano在CentOS上的安装和使用
    CentOS 7 安装php5.6,Nginx,Memcached环境及配置
    PhpStorm 2017.1安装及破解过程
    在唯一密钥属性“name”设置为“ExtensionlessUrlHandler-Integrated-4.0”时,无法添加类型为“add”的重复集合项
    获取含有字符串数组里元素的数据,并批量删除
    如何去掉browserLinkSignalR
    使用VS2015开发asp程序让IIS express 允许的父路径的方法
  • 原文地址:https://www.cnblogs.com/s-kaikai/p/11801306.html
Copyright © 2011-2022 走看看