ssm框架配置

web.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    	http://java.sun.com/xml/ns/j2ee/web-app_4_0.xsd">


	<!-- 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:applicationContext.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<url-pattern>/</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>

	<!-- Session -->
	<session-config>
		<session-timeout>15</session-timeout>
	</session-config>
	

</web-app>

applicationContext.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:contxt="http://www.springframework.org/schema/context" 
       xmlns:p="http://www.springframework.org/schema/p"
       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">
    <import resource="classpath:spring-dao.xml"/>
    <import resource="classpath:spring-service.xml"/>
    <import resource="classpath:spring-mvc.xml"/>
    
</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>
    <settings>
        <!--日志设置-->
        <setting name="logImpl" value="LOG4J"/>
    </settings>
</configuration>

spring-dao.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:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    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">
 
 	<!-- 关联数据库的配置文件  -->
 	<context:property-placeholder location="classpath:db.properties"/>
 	
 	<!-- 数据库连接池
 		连接池:
 			dbcp:半自动化,不能自动连接
 			c3p0:自动化操作(自动化的加载配置文件,并且可以自动设置到对象中!)
 			druid:
 			hicari:
 	 -->
 	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
 		<property name="driverClass" value="${jdbc.driver}"/>
 		<property name="jdbcUrl" value="${jdbc.url}"/>
 		<property name="user" value="${jdbc.username}"/>
 		<property name="password" value="${jdbc.password}"/>
 		
 		<!-- c3p0连接池私有属性 -->
 		<property name="maxPoolSize" value="30"/> 			<!-- 最多30个连接 -->
 		<property name="minPoolSize" value="10"/> 			<!-- 最少10个连接 -->
 		<!-- 关闭后不自动提交 -->
 		<property name="autoCommitOnClose" value="false"/>
 		<!-- 允许连接超时时间 -->
 		<property name="checkoutTimeout" value="10000"/>
 		<!-- 当获取连接失败 重新尝试连接次数 -->
 		<property name="acquireRetryAttempts" value="2"/>
 	</bean>
 	
 	<!-- sqlsessionFactory -->
 	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
 		<property name="dataSource" ref="dataSource"/>
 		<!-- 映射 DML 语法 只要文件夹变蓝色 就是classpath 所以要有个mapper文件夹 下面所有的.xml都会映射-->
		<property name="mapperLocations" value="classpath:mapper/*.xml"/>
 		<!-- 绑定Mybatis配置文件 -->
 		<property name="configLocation" value="classpath:mybatis-config.xml"/>
 	</bean>
 	
 	<!-- 配置dao接口扫描包,动态实现dao接口可以注入到Spring容器中 -->
 	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
 		<!-- 注入sqlsessionFactory -->
 		<property name="sqlSessonFactoryBeanName" value="sqlSessionFactory"/>
 		<!-- 要扫描的dao包 -->
 		<property name="basePackage" value="zcu.oa.dao"/>
 	</bean>
 	
 
</beans>

spring-mvc.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:contxt="http://www.springframework.org/schema/context" 
       xmlns:p="http://www.springframework.org/schema/p"
       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">

	<!-- 注解驱动 -->
	<mvc:annotation-driven/>
	<!-- 静态资源过滤 -->
	<mvc:default-servlet-handler/>
	<!-- 扫描包:controller -->
	<contxt:component-scan base-package="zcu.oa.controller"/>
	<!-- 视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    
</beans>

spring-service.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:p="http://www.springframework.org/schema/p" 
    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">
 	
 	<!-- 扫描Service下的包 -->
 	<context:component-scan base-package="zcu.oa.service"/>
 
 	<!-- 启动 mvc 的常用注解 -->
    <mvc:annotation-driven/>

    <!--将所有的静态资源,交给 Servlet 处理-->
    <mvc:default-servlet-handler/>
 	
 	<!-- 声明事务配置 -->
 	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 		<!-- 注入数据源 -->
 		<property name="dataSource" ref="dataSource"/>
 	</bean>
 	
 	
 	<!-- 将所有业务类注入到Spring中,可以通过配置或注解实现 
 	<bean id="" class=""></bean>  -->
 	
 	<!-- aop事务支持   -->
 	
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值