打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
spring配置文件说明
<!-- 头文件,主要注意一下编码 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- 整个配置文件的根结点,包括一个或多个bean -->
<!-- 第一行xmlns与第二行xmlns:xsi最基本的命名空间定义
xmlns:context启用自动扫描或注解装配时的命名空间
xmlns:aop启用aop功能时的命名空间
xmlns:tx启用声明事务时的命名空间
xsi:schemaLocation与上述命名空间定义相配套的schema定义文件的装载路径
default-autowire自动付值bean对象中的属性值,有四种类型:byname,bytype,constructor,autodetect,no(默认)
default-lazy-init默认延迟加载.默认值为false,会加载全部对象实例图,使项目启动速度变慢。在项目开发中可用true,项目运行中要用false
default-dependency-check:依赖检查模式
default-init-method:初始化方法,此方法将在BeanFactory创建JavaBean实例之后,在向应用层返回引用之前执行。 
default-merge
default-destroy-method:销毁方法。此方法将在BeanFactory销毁的时候执行,一般用于资源释放。-->
<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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName" default-lazy-init="true"
default-dependency-check="none"
default-init-method="" default-merge="false" default-destroy-method="">
<!-- 建立数据源 -->
<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&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>

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ssh 中使用c3p0 的连接池配置
SSH整合(struts2.2.1 + spring3.0 + hibernate3.3)
Spring-3.2.4 + Quartz-2.2.0集成实例
springMVC 文件上传(一)
maven搭建springmvc+spring+mybatis实例
SpringSecurity3整合CAS实现单点登录
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服