Spring web mvc && mybatis框架配置文件
Posted 小灰灰菜鸟程序员
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring web mvc && mybatis框架配置文件相关的知识,希望对你有一定的参考价值。
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:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
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: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/util http://www.springframework.org/schema/util/spring-util-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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 采用new GregorianCalendar() -->
<bean id="cms_test" class="java.util.GregorianCalendar"></bean>
<bean id="cms_test1" class="java.util.GregorianCalendar" factory-method="getInstance"></bean>
<!-- 采用c1.getTime(),对象工厂方法 -->
<!-- <bean id="cms_test_date" factory-bean="cms_test1" factory-method="getTime"></bean> -->
<bean id="cms_example" lazy-init="true" destroy-method="mydestroy" init-method="init" scope="singleton" class="qizhi.test.ExampleBean"></bean>
<bean id="cms_computer" class="qizhi.test.Computer" >
<!-- 信息set注入 -->
<property name="cpu" value="骁龙"></property>
<property name="hdd" value="索尼"></property>
<property name="mainbord" value="华为"></property>
</bean>
<!-- 构造器注入 -->
<bean id="cms_phone" class="qizhi.test.Phone">
<constructor-arg index="0" value="高通"></constructor-arg>
<constructor-arg index="1" value="2G"></constructor-arg>
</bean>
<bean id="cms_student" class="qizhi.test.Student">
<!-- 利用set注入Computer ref引用 -->
<property name="c" ref="cms_computer"> </property>
<!-- 利用set注入Phone -->
<property name="p" ref="cms_phone"> </property>
</bean>
<bean id="cms_student1" class="qizhi.test.Student" autowire="byType">
</bean>
<!-- <bean id="date" class="java.util.Date"></bean> -->
<bean id= "cms_message" class="qizhi.test.MessageBean" >
<property name="name" value="root"></property>
<property name="age" value="18"></property>
<property name="birth" value="2015-04-17"></property>
<property name="friends">
<list>
<value>tom</value>
<value>marry</value>
<value>jack</value>
</list>
</property>
<property name="cities">
<set>
<value>北京</value>
<value>浙江</value>
<value>上海</value>
</set>
</property>
<property name="books">
<map>
<entry key="1001" value="java基础"></entry>
<entry key="1002" value="javaWeb"></entry>
</map>
</property>
<property name="db">
<props>
<prop key="username">liuzhihui</prop>
<prop key="password">123456</prop>
<prop key="driver">com.mysql.jdbc.Driver</prop>
</props>
</property>
</bean>
<!-- 定义List对象 -->
<util:list id="someList">
<value>晓明</value>
<value>酷哥</value>
</util:list>
<util:set id="someSet">
<value>北京</value>
<value>海南</value>
</util:set>
<util:map id="someMap">
<entry key="1003" value="mySql基础"></entry>
<entry key="1004" value="Spring开发"></entry>
</util:map>
<util:properties id="someProps">
<prop key="username">#{dbParams.user}</prop>
<prop key="password">#{dbParams.password}</prop>
<prop key="driver">#{dbParams.driver}</prop>
</util:properties>
<!--读取db.properties文件,形成一个Properties对象 --><util:properties id="dbParams" location="classpath:db.properties">
</util:properties>
<bean id="cms_all" class="qizhi.test.MessageBean">
<property name="name" value="#{dbParams.user}"></property>
<property name="friends" ref="someList"></property>
<property name="cities" ref="someSet"></property>
<property name="books" ref="someMap"></property>
<!-- <property name="db" ref="someProps"></property> -->
<propertyname="db" ref="dbParams"></property>
</bean>
以上是关于Spring web mvc && mybatis框架配置文件的主要内容,如果未能解决你的问题,请参考以下文章
Spring MVC ResponseEntity Hystrix 回退
如何在 REST API 中使用带有 spring mvc 的版本?
如何使用 Spring MVC & Security、Jasig CAS 和 JSP 视图在 Spring Boot 2 中配置 UTF-8?