SSM框架基础配置

来源:互联网 发布:linux怎么打开found 编辑:程序博客网 时间:2024/06/01 09:19
<!-- 配置Spring-->
<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath:verifyProject/mvc/applicationContext/ac.xml</param-value>
 </context-param>
 <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <!-- 配置Spring-->
 
  <!--配置SpringMVC  -->
    <servlet>
        <servlet-name>Login</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:*-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Login</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>
 
  <!--配置SpringMVC  -->

*************************web-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: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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        
     <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
         <property name="mappings">
             <props>
                 <prop key="*.action">
                     multiActionController
                 </prop>
             </props>
         </property>
     </bean>
     
     <bean id="multiActionController" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController" >
           <property name="delegate" ref="loginControllers"/>
     </bean>

    <bean id="loginControllers" class="verifyProject.mvc.controller.LoginControllers">
         <property name="userInfoService" ref="userInfoService"/>
    </bean>
        
</beans>

************************************mybatis-config.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>
      <typeAliases>
        <typeAlias type="verifyProject.mvc.vo.Userinfo" alias="Userinfo"/>
      </typeAliases>
  </configuration>

***********************************applacationContext.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: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/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">
    
    
       <bean id="db" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
               <property name="acquireIncrement" value="3"></property>
               <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
               <property name="maxPoolSize" value="10"></property>
               <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/wc"></property>
               <property name="user" value="root"></property>
               <property name="password" value="123456"></property>
               <property name="minPoolSize" value="1"></property>
               <property name="initialPoolSize" value="1"></property>
               <property name="maxIdleTime" value="60"></property>
       </bean>
        <!--相当于关联mybatis和spring,顺便设置数据库连接参数  -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="configLocation" value="classpath:myBatisConfig.xml"></property>
            <property name="dataSource"  ref="db"></property>
            <property name="mapperLocations" value="classpath:verifyProject/mvc/mapper/*.xml"></property>
        </bean>
        <!--相当于dao层实现 -->
        <bean id="mapperFactoryBean" class="org.mybatis.spring.mapper.MapperFactoryBean">
            <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
            <property name="mapperInterface" value="verifyProject.mvc.dao.UserinfoMapper"></property>
        </bean>
        
       <bean id="userInfoService" class="verifyProject.mvc.service.UserInfoServiceImp">
               <property name="UserinfoMapper" ref="mapperFactoryBean"></property>
       </bean>
       
</beans> 


原创粉丝点击