• 简单的spring--mvc整合


    <?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:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx  
        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
        
        <!-- 指定扫描包,并注入注解类 -->
        <context:component-scan base-package="com.chinasoft.ssm" /> 
        
        <!--读入配置文件 -->
        <bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="locations">
                    <value>classpath*:jdbc.properties</value>
                </property>
        </bean>
        
        <!-- 配置数据源 -->
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  destroy-method="close">  
             <property name="driverClassName" value="${jdbc.driverClassName}" />
             <property name="url" value="${jdbc.url}" />
             <property name="username" value="${jdbc.username}" />
             <property name="password" value="${jdbc.password}" />
        </bean> 
        <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
            <property name="dataSource" ref="dataSource" /> 
            <!-- 文件映射器,指定类文件 -->
            <!--  <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/> --> 
            <!-- 自动扫描mapping.xml文件 -->  
            <property name="mapperLocations" value="classpath:com/chinasoft/ssm/mapper/*.xml"></property>  
        </bean>  
        <!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
            <property name="basePackage" value="com.chinasoft.ssm.dao"/>  
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
        </bean>  
         
        <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->  
        <bean id="transactionManager"  
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
            <property name="dataSource" ref="dataSource" />  
        </bean> 

         

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <display-name>SSM</display-name>
      <!-- 项目从此处开始进入 -->
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <!-- 项目启动的时候读取配置文件 -->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mybatis.xml</param-value>
      </context-param>
      <!-- 当页面访问时请求经过DispatcherServlet -->
      <servlet>
            <servlet-name>springMVC</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:spring-mybatis.xml</param-value>
            </init-param>    
      </servlet>
      <!-- 加载一系列的servlet类 -->
      <servlet>
        <servlet-name>SafeCodeImageServlet</servlet-name>
        <servlet-class>com.chinasoft.ssm.servlet.SafeCodeImageServlet</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>CheckCode</servlet-name>
        <servlet-class>com.chinasoft.ssm.servlet.CheckCode</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>ImageServlet</servlet-name>
        <servlet-class>com.chinasoft.ssm.servlet.ImageServlet</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>graphicsImage</servlet-name>
        <servlet-class>com.chinasoft.ssm.servlet.graphicsImage</servlet-class>
      </servlet>
      <!-- servlet类的映射文件 -->
      <servlet-mapping>
        <servlet-name>SafeCodeImageServlet</servlet-name>
        <url-pattern>/servlet/SafeCodeImageServlet</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
          <servlet-name>springMVC</servlet-name>
          <url-pattern>*.mvc</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>CheckCode</servlet-name>
        <url-pattern>/servlet/CheckCode</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>ImageServlet</servlet-name>
        <url-pattern>/servlet/ImageServlet</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>graphicsImage</servlet-name>
        <url-pattern>/servlet/graphicsImage</url-pattern>
      </servlet-mapping>
      <!-- 加载拦截器,此处为一个编码格式拦截器 -->
        <filter>  
            <filter-name>CharacterEncodingFilter</filter-name>  
            <filter-class>
                org.springframework.web.filter.CharacterEncodingFilter
            </filter-class>  
            <init-param>  
                <param-name>encoding</param-name>  
                <param-value>UTF-8</param-value>  
            </init-param>  
            
        </filter>
        <!-- 配置拦截器的作用范围 -->
        <filter-mapping>  
            <filter-name>CharacterEncodingFilter</filter-name>  
            <url-pattern>/*</url-pattern>  
        </filter-mapping>
        <!-- 自己配置的验证登录的拦截器 -->
        <filter>
            <filter-name>checkLogin</filter-name>
            <filter-class>com.chinasoft.ssm.util.CheckLogin</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>checkLogin</filter-name>
            <url-pattern>/index.jsp</url-pattern>
        </filter-mapping>
    </web-app>

    <!-- 使用annotation注解方式配置事务 -->
          <tx:annotation-driven transaction-manager="transactionManager"/>

    </beans>
  • 相关阅读:
    Installshield 添加应用程序到防火墙例外
    服务器表导入到本地数据库SQL语句
    【转】13个JavaScript图表(JS图表)图形绘制插件
    【转】20个简化开发任务的 JavaScript库
    【转】8 个效果惊人的 WebGL/JavaScript 演示
    【转】JavaScript 3D图表
    VMware显示错误:“未能锁定文件 无法打开磁盘 ..*.vmdk 或者某一个快照所依赖的磁盘。”解决办法
    Spring HTTP invoker简介
    【转】在Ubuntu下建立Eclipse的Android开发环境
    【转】在NetBeans上搭建Android SDK环境
  • 原文地址:https://www.cnblogs.com/feitianshaoxai/p/6605997.html
Copyright © 2020-2023  润新知