SSM(Spring+SpringMVC+Mybatis)基础配置文件

applicationContext

<?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: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/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc.xsd">
		
		<context:component-scan base-package="com.wb.graduation.service"></context:component-scan>
		<!-- 配置数据库 -->
		<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		   <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/gradation"></property>
		   <property name="user" value="root"></property>
		   <property name="password" value="111"></property>
		   <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
		
			<!-- 配置获取连接等待超时的时间 -->
		   <property name="maxWait" value="60000" />
		   <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		   <property name="timeBetweenEvictionRunsMillis" value="60000" />
	       <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		   <property name="maxActive" value="300" />
           <property name="minEvictableIdleTimeMillis" value="300000" />
		   <property name="testWhileIdle" value="true" />
		   <property name="testOnBorrow" value="false" />
		   <property name="testOnReturn" value="false" />
		</bean>
		<!-- 定义mybatis的SqlSessionFactory -->
		<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		    <property name="dataSource" ref="dataSource"></property>
		</bean>
		
		<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		    <property name="basePackage" value="com.wb.graduation.mapper"></property>
		</bean>
</beans>

springMVC-servlet

<?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: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/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc.xsd">

	    <!-- 开启SpringMVC -->
        <context:component-scan base-package="com.wb.graduation.controller"></context:component-scan>
        <!--定义包扫描注解-->
        <mvc:annotation-driven></mvc:annotation-driven>
        <!-- 视图解析器 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        	<property name="prefix" value="/"></property>
        	<property name="suffix" value=".jsp"></property>
        </bean>
</beans>

web

<?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" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>graduation</display-name>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  
  <!-- 配置Spring监听器 -->
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 过滤器 -->
  <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>
  <!-- 分发器 -->
  <servlet>
 	<servlet-name>springMVC</servlet-name>
 	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--通过初始化参数指定SpringMVC配置文件的位置,进行关联-->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springMVC-servlet.xml</param-value>
        </init-param>
        <!-- 启动顺序,数字越小,启动越早 -->
	<!-- load-on-startup:表示启动容器时刻初始化该servlet的顺序-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
     <servlet-name>springMVC</servlet-name>
     <url-pattern>*.action</url-pattern>
  </servlet-mapping>
</web-app>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值