ssm配置文件

1. mybatis核心配置文件 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>
		<package name="edu.fan.ssm.crm.pojo"/>
	</typeAliases>
</configuration>

2.springmvc管理mybatis数据库 applicationContext-mapper.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"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
						http://www.springframework.org/schema/mvc 
						http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context-4.0.xsd 
						http://www.springframework.org/schema/aop 
						http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
						http://www.springframework.org/schema/task
				   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
						http://code.alibabatech.com/schema/dubbo        
						http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	<!--1. 连接外部数据库文件 -->
	<context:property-placeholder location="classpath:db.properties"/>
	
	<!--2. 管理数据源 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidAbstractDataSource">
		<property name="driverClassName" value="${jdbc.driver}"/>
		<property name="url" value="${jdbc.url}"/>
		<property name="username" value="${jdbc.username}"/>
		<property name="password" value="${jdbc.password}"/>
	</bean>
	<!-- 3.管理会话工厂 -->
	<bean id="sqlSesionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 3.1注入数据源 -->
		<property name="dataSource" ref="dataSource"/>
		<!-- 3.2加载mybatis的核心配置文件 -->
		<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
	</bean>
	
	<!-- 4.管理代理对象 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 扫描包 -->
		<property name="basePackage" value="edu.fan.ssm.crm.mapper"/>
	</bean>
</beans>

3.springmvc事务管理器 applicationContext-transaction.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"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
						http://www.springframework.org/schema/mvc 
						http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context-4.0.xsd 
						http://www.springframework.org/schema/aop 
						http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
						http://www.springframework.org/schema/task
				   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
						http://code.alibabatech.com/schema/dubbo        
						http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	<!-- spring管理事务 
		方式:
			1.注解
			2.配置文件:声明式管理事务:规范代码开发
	-->
	<!-- 1.配置事务管理器 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 1.1注入数据源 -->
		<property name="dataSource" ref="dataSoure"/>
	</bean>
	
	<!-- 2.声明通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="update*" propagation="REQUIRED"/>
			<tx:method name="insert*" propagation="REQUIRED"/>
			<tx:method name="delete*" propagation="REQUIRED"/>
			<tx:method name="query*" propagation="REQUIRED"/>
			<tx:method name="update*" propagation="SUPPORTS" read-only="true"/>
		</tx:attributes>
	</tx:advice>
	<!-- 3.配置切面 -->
	<aop:config>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="execution(* edu.fan.ssm.crm.service.*.*(..))"/>
	</aop:config>
</beans>

4.springmvc管理service applicationContext-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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
						http://www.springframework.org/schema/mvc 
						http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context-4.0.xsd 
						http://www.springframework.org/schema/aop 
						http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
						http://www.springframework.org/schema/task
				   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
						http://code.alibabatech.com/schema/dubbo        
						http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
						
	<!-- spring管理service:扫描 @Service 注解的类 -->
	<context:component-scan base-package="edu.fan.ssm.crm.service"/>
</beans>

5.springmvc核心配置文件 springmvc.xml

<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"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
		                   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
		                   http://www.springframework.org/schema/mvc 
		                   http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
		                   http://www.springframework.org/schema/context 
		                   http://www.springframework.org/schema/context/spring-context-4.0.xsd 
		                   http://www.springframework.org/schema/aop 
		                   http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
		                   http://www.springframework.org/schema/tx 
		                   http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		                   http://www.springframework.org/schema/task
   		                   http://www.springframework.org/schema/task/spring-task-4.0.xsd
		                   http://code.alibabatech.com/schema/dubbo        
		                   http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	
<!--1. 配置扫描器 -->
	<context:component-scan base-package="edu.fan.ssm.crm.controller"/>
	
	<!--2. 配置注解驱动,可以代替上面的两种加载方式 -->
	<mvc:annotation-driven />
	
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/"/>
		<property name="suffix" value=".jsp"/>
	</bean>
	
	<!--3. 加载spring其他的配置文件 -->
	<import resource="classpath:spring/applicationContext-*.xml"/>	
</beans>

6.配置web,xml

<?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_2_5.xsd" 
      id="WebApp_ID" version="2.5">
  <display-name>crm_ssm</display-name>
  <servlet>
    <servlet-name>crm_ssm</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>crm_ssm</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值