zoukankan      html  css  js  c++  java
  • SSM 三大框架整合

    SSM 三大框架整合

     


    1, 准备环境
    1.1 为每个War包工程创建一个Server


    那么 添加了Server后需要对每一个Server进行配置:
    以console为例子:
    设置timeout的时间为300


    去掉项目名


    剩下的几个Server 需要改端口号:


    2, 导入Jar包
    在父工程的pom文件中导入项目开发所需要的jar包:
    pom.xml:

     pom.xml


    3,Druid
    以往配置数据库连接池我们大多使用C3P0,jdbc等, 但是现在开始使用Druid.


    4, Servlet-api.jar

    把这个jar包单独拿出来提是因为在Tomcat 7中 使用的是3.0版本, 而我们通过pom导入的只能够是2.5, 所以这里Apache专门开发了一个jar包来替代这个.(这里所说的替代只是在编码中可以使用, 添加了provided关键字, 并不会被编译)

    需要在在每个子项目pom.xml添加:

    1 <!-- Tomcat7 servlet-api -->
    2 <dependency>
    3     <groupId>org.apache.tomcat</groupId>
    4     <artifactId>tomcat-jsp-api</artifactId>
    5     <scope>provided</scope>
    6 </dependency>


    5, 整合Spring+Mybatis

    Babasport-service-product  为安例进行整合


    想看一眼product目录结构:


    web.xml:

    复制代码
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     6     
     7     <!-- 上下文的位置 -->
     8     <context-param>
     9         <param-name>contextConfigLocation</param-name>
    10         <param-value>classpath:application-context.xml</param-value>
    11     </context-param>
    12     
    13     <!-- Spring监听器 -->
    14     <listener>
    15         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    16     </listener>
    17 </web-app>
    复制代码

    application-context.xml:spring配置文件

    复制代码
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:task="http://www.springframework.org/schema/task"
        xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-4.0.xsd 
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
            http://www.springframework.org/schema/task
               http://www.springframework.org/schema/task/spring-task-4.0.xsd
            http://code.alibabatech.com/schema/dubbo        
            http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
            
            <!-- 配置 连接池 事务 扫描 读取jdbc.properties mybatis工厂  solr redis-->
            <import resource="config/*.xml"/>
            
    </beans>
    复制代码

    mybatis=config.xml

    复制代码
     1 <?xml version="1.0" encoding="UTF-8" ?>
     2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
     3 "http://mybatis.org/dtd/mybatis-3-config.dtd">
     4 
     5 <configuration>
     6     <!-- 别名 -->
     7     <typeAliases>
     8         <package name="cn.itcast.core.bean"/>
     9     </typeAliases>
    10     
    11     <!-- Mapper.xml所在位置 
    12     <mappers>
    13         <package name="cn.itcast.core.dao"/>
    14     </mappers>
    15     -->
    16 </configuration>
    复制代码


    anoaction.xml: 扫描设置

     View Code

    jdbc.xml: JDBC配置文件

     View Code

    mybatis.xml: mybatis配置文件

     View Code

    properties.xml: 读取属性文件

     View Code

    transaction.xml:事务配置文件

     View Code


    6, 整合Spring

    Login/Console/Portal 都是输入Controller层, 所以这三个project都需要做此配置.
    这里以Console为例子:
    先看一下Console project整体目录结构:


    web.xml:

    复制代码
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     6     
     7     <!-- 前端控制器 -->
     8     <servlet>
     9         <servlet-name>console</servlet-name>
    10         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    11         <init-param>
    12             <param-name>contextConfigLocation</param-name>
    13             <!-- 默认读取的是 WEB-INF/console-servlet.xml -->
    14             <param-value>classpath:springmvc-console.xml</param-value>
    15         </init-param>
    16     </servlet>
    17     
    18     <servlet-mapping>
    19         <servlet-name>console</servlet-name>
    20         <!-- 
    21             /*: 拦截视图请求: .jsp  .js  .css  几乎不用,配置静态资源过滤
    22             /: 拦截所有,不拦截.jsp 文件, 但是同样拦截.js .css  如果使用也需要配置静态资源过滤(前台系统使用)
    23             *.do:拦截所有以.do请求, 后台开发应用*.do
    24          -->
    25         <url-pattern>*.do</url-pattern>
    26     </servlet-mapping>
    27 </web-app>
    复制代码


    springmvc-console.xml:Springmvc配置文件

     View Code



  • 相关阅读:
    动态网页技术--JSP(5)
    动态网页技术--JSP(4)
    动态网页技术--JSP(3)
    动态网页技术--JSP(2)
    动态网页技术--JSP(1)
    动态网页技术--Servlet
    TomCat服务器搭建
    06_多线程
    05_进程间通信 IPC
    04_进程池
  • 原文地址:https://www.cnblogs.com/du-0210/p/8426528.html
Copyright © 2011-2022 走看看