SSM整合之applicationContext.xml(也叫Mybatis-config.xml)文件的详细配置加解释说明,web.xml文件的配置

ssm整合,mybatis-config.xml文件的配置信息:

applicationContext.xml:


<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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
	   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
">

	
	<context:component-scan base-package="com.macw" />

    
    <context:property-placeholder location="classpath:jdbc.properties" system-properties-mode="NEVER">context:property-placeholder>
    
    <bean id="ds" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="password" value="${password}"/>
        <property name="username" value="${username}"/>
        <property name="driverClassName" value="${driverClassName}"/>
        <property name="url" value="${url}"/>
        <property name="maxWait" value="${maxWait}"/>
        <property name="maxActive" value="${maxActive}"/>
        <property name="initialSize" value="${initialSize}"/>
    bean>
    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="ds"/>
        
        <property name="mapperLocations">
            <list>
                
                <value>classpath:com/macw*.xmlvalue>
            list>
        property>
        
        <property name="typeAliasesPackage" value="com.macw.entity"/>
        <property name="configurationProperties">
            <props>
                <prop key="logImpl">LOG4Jprop>
            props>
        property>
    bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        
        <property name="basePackage" value="com.macw.dao"/>
        
    bean>
    
    
    <context:component-scan base-package="com.macw.service.impl"/>
    
    <bean id="tm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="ds"/>
    bean>
    
    <tx:advice id="ct" transaction-manager="tm">
        
        <tx:attributes>
            
            <tx:method name="select*" read-only="true"/>
            
            <tx:method name="*" propagation="REQUIRED"/>
        tx:attributes>
    tx:advice>
    
    <aop:config>
        <aop:pointcut id="pc" expression="execution(* com.macw.service..*.*(..))"/>
        <aop:advisor advice-ref="ct" pointcut-ref="pc"/>
    aop:config>
beans>

小配置文件jdbc.properties

username=hr
password=hr
url=jdbc:oracle:thin:@localhost:1521:xe
driverClassName=oracle.jdbc.OracleDriver
initialSize=10
maxActive=15
maxWait=10000

web.xml文件配置信息:



<web-app version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">



  
  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>/WEB-INF/mybatis-config.xmlparam-value>
  context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>
  
  <servlet>
    <servlet-name>springmvcservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>/WEB-INF/spring-config.xmlparam-value>
    init-param>
    <load-on-startup>1load-on-startup>
  servlet>
  <display-name>Archetype Created Web Applicationdisplay-name>

  <servlet-mapping>
    <servlet-name>springmvcservlet-name>
    <url-pattern>/url-pattern>
  servlet-mapping>

  
  <filter>
    <filter-name>encodingFilterfilter-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>encodingFilterfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>
  
  <servlet-mapping>
    <servlet-name>defaultservlet-name>
    <url-pattern>*.jsurl-pattern>
    <url-pattern>*.cssurl-pattern>
    <url-pattern>*.jpgurl-pattern>
    <url-pattern>*.pngurl-pattern>
    <url-pattern>*.PNGurl-pattern>
    <url-pattern>*.gifurl-pattern>
    <url-pattern>*.jsonurl-pattern>
    <url-pattern>*.htmlurl-pattern>
  servlet-mapping>

  
  <error-page>
    <error-code>404error-code>
    <location>/404.htmllocation>
  error-page>
  <welcome-file-list>
    <welcome-file>index.jspwelcome-file>
  welcome-file-list>

web-app>

你可能感兴趣的:(Spring,+Spring,MVC)