springMVC,mybaits整合

http://haohaoxuexi.iteye.com/blog/1843309

这篇说的很清楚了,之前也是被jar包版本搞醉了,特此记录

<?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:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="  
    http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/tx   
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   
    http://www.springframework.org/schema/context   
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	<!-- Root Context: defines shared resources visible to all other web components -->
	<!-- 通过component-scan 让Spring扫描org.swinglife.controller下的所有的类,让Spring的代码注解生效 -->
	<context:component-scan base-package="com.hehe"></context:component-scan>
    <context:property-placeholder location="classpath:jdbc.properties"/>  
    
   <!--创建jdbc数据源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<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>
   
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
       <property name="dataSource" ref="dataSource" />  
       <property name="mapperLocations" value="classpath:com/hehe/mapper/*.xml"/>  
       <property name="typeAliasesPackage" value="com.hehe.pojo" />  
    </bean>  
   
    <!-- dao --> 
    <bean id="messageDao" class="org.mybatis.spring.mapper.MapperFactoryBean">  
       <property name="mapperInterface" value="com.hehe.mapper.MessageMapper" />  
       <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
    </bean>
    
</beans>



<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
				http://www.springframework.org/schema/aop
				http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 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">
	<!-- 加载Spring的全局配置文件 -->
	<beans:import resource="root-context.xml"/>
	<!-- SpringMVC配置 -->
	
	<!-- 配置SpringMVC的视图渲染器, 让其前缀为:/ 后缀为.jsp  将视图渲染到/page/<method返回值>.jsp中 -->
	<beans:bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/" p:suffix=".jsp">
		</beans:bean>
</beans:beans>



springMVC,mybaits整合

你可能感兴趣的:(springMVC,mybaits整合)