<?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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 数据库连接 -->
<bean id="mydatasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="username" value="root">
</property>
<property name="password" value="mysqladmin">
</property>
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/kingslanding">
</property>
</bean>
<!-- 返回json 方法 需要导入 jackson-annotations.jar,jackson-core.jar,jackson-databind.jar-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
<!-- 在Spring中生成一个sqlsessionfactory对象 -->
<bean id="sqlsessionfactorybean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="mydatasource">
</property>
<property name="mapperLocations" value="classpath:org/kingsanding/dao/*/*.xml">
</property>
</bean>
<!-- 根据MapperDao生成Dao对象实例 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.kingsanding.dao">
</property>
<!-- 指定@MyBatisDao所在位置 -->
<property name="annotationClass" value="org.kingsanding.utils.MyBatisDao">
</property>
<!-- 自动注入sqlsessionfactory -->
</bean>
<!-- Spring MVC -->
<!-- 启动Spring的组件自动扫描机制 -->
<context:component-scan base-package="org.kingsanding" />
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>
</beans>
原文:http://www.cnblogs.com/duoqingxiaohao/p/4988488.html