http://haohaoxuexi.iteye.com/blog/1843309 web
這篇說的很清楚了,以前也是被jar包版本搞醉了,特此記錄 spring
<?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>