以下是详解Spring的applicationContext.xml文件代码:
<!-- 头文件,主要注意一下编码 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <!-- 建立数据源 -->
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <!-- 数据库驱动,我这里使用的是Mysql数据库 -->
  <property name="driverClassName">
   <value>com.mysql.jdbc.Driver</value>
  </property>
  <!-- 数据库地址,这里也要注意一下编码,不然乱码可是很郁闷的哦! -->
  <property name="url">
   <value>
       jdbc:mysql://localhost:3306/tie?useUnicode=true&amp;characterEncoding=utf-8
   </value>
  </property>
  <!-- 数据库的用户名 -->
  <property name="username">
   <value>root</value>
  </property>
  <!-- 数据库的密码 -->
  <property name="password">
   <value>123</value>
  </property>
 </bean>
 <!-- 把数据源注入给Session工厂 -->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <!-- 配置映射文件 -->
  <property name="mappingResources">
   <list>
    <value>com/alonely/vo/User.hbm.xml</value>
   </list>
  </property>
 </bean>
 <!-- 把Session工厂注入给hibernateTemplate -->
 <!-- 解释一下hibernateTemplate:hibernateTemplate提供了很多方便的方法,在执行时自动建立 HibernateCallback 对象,例如:load()、get()、save、delete()等方法。 -->
 <bean id="hibernateTemplate"
  class="org.springframework.orm.hibernate3.HibernateTemplate">
  <constructor-arg>
   <ref local="sessionFactory" />
  </constructor-arg>
 </bean>
 <!-- 把DAO注入给Session工厂 -->
 <bean id="userDAO" class="com.alonely.dao.UserDAO">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>
 <!-- 把Service注入给DAO -->
 <bean id="userService" class="com.alonely.service.UserService">
  <property name="userDAO">
   <ref local="userDAO" />
  </property>
 </bean>
 <!-- 把Action注入给Service -->
 <bean name="/user" class="com.alonely.struts.action.UserAction">
  <property name="userService">
   <ref bean="userService" />
  </property>
 </bean>
</beans>

Spring的applicationContext.xml文件的更多相关文章

  1. ApplicationContext.xml文件详解

    想必用过Spring的程序员们都有这样的感觉,Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好).以至于有的初学者都不知道Spring配置文件的意思,就拿来用了.所以今天我给大家详 ...

  2. Spring配置文件详解 - applicationContext.xml文件路径

    spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...

  3. Spring配置文件详解 – applicationContext.xml文件路径

    Spring配置文件详解 – applicationContext.xml文件路径 Java编程                 spring的配置文件applicationContext.xml的默 ...

  4. Spring中加载ApplicationContext.xml文件的方式

    Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...

  5. 当你的Spring IOC 容器(即applicationContext.xml文件)忘记配到web.xml 文件中时

    当你的Spring IOC 容器忘记配到web.xml 文件中时,启动服务器就会报错. 部分错误如下: Caused by: org.springframework.beans.factory.NoS ...

  6. Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

    Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

  7. Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)

    <bean id="propertyConfigurer" class="com.****.framework.core.SpringPropertiesUtil& ...

  8. spring将service添加事务管理,在applicationContext.xml文件中的设置

    在applicationContext.xml文件中的设置为: <beans> <bean id="sessionFactory" class="org ...

  9. web.xml中配置Spring中applicationContext.xml的方式

    2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...

随机推荐

  1. 从Swap函数谈加法溢出问题

    1.      初始题目 面试题:). 这个题目太经典,也太简单,有很多人都会不假思索结出答案: //Code 1 void Swap(int* a, int* b) { *a = *a + *b; ...

  2. kvm安装及配置

     yum install kvm libvirt python-virtinst qemu-kvm virt-viewer bridge-utils virt-install 修改网卡信息 /etc/ ...

  3. 传送门(portal)

    Linux: #RHEL/CentOS/fedora系列为主 Basis: Commands: Services: SpamAssassin: Tomcat: Hadoop: Hive: Pig: Z ...

  4. Android 5.0 新特性

    Material Design Material Design简介 Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干 ...

  5. Ubuntu安装gevent

    今天在安装包的过程中,按照网上的文章,出错,找了很久,最后才安装成功,希望能解决以后大家遇到的问题 Ubuntu安装gevent Gevent是一个基于greenlet的Python的并发框架,以赖于 ...

  6. javascript 【js‘s word】

    http://mp.weixin.qq.com/s?__biz=MjM5MzY2NDY0Ng==&mid=214013689&idx=1&sn=21e03f6c7bf73893 ...

  7. android使用adb installapk出现can't find **.apk to install

    1. 有时候我们需要在使用ADT命令的adb安卓外部命令的时候出现下面的问题 出现上面的问题,其实是我们的apk方的文件不对,具体是什么问题怎么改路径我就没有深入研究了,.我查阅了好多资料才发现并不是 ...

  8. MongoDB的查询

    一.Find操作 二.分页和排序 三.游标的使用 一.Find查询 事前准备:插入如下数据 db.Students.insert([ { _id:1, name:"Zhao", a ...

  9. Android eclipse - aapt.exe has stopped working.

    今天在修改Android的布局文件的时候,发现每保存一次,就提示: aapt.exe has stopped working(appt.exe已停止工作).很是郁闷,当时Android控制台已经提示错 ...

  10. OC基础-day06

    #pragma mark - Day06_01_点语法 1. 点语法. 1). 如果要访问对象的属性,还要去调用属性对应的setter getter方法.好烦躁好烦躁. 2). 点语法的作用: 快速调 ...