Spring的applicationContent.xml配置详解
来源:互联网 发布:matlab随机森林算法 编辑:程序博客网 时间:2024/06/03 04:42
想必用过Spring的程序员们都有这样的感觉,Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好)。
以至于有的初学者都不知道Spring配置文件的意思,就拿来用了。所以今天我给大家详细解释一下
Spring的applicationContext.xml文件。Ok,还是通过代码加注释的方式为大家演示:
以下是详解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&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>
阅读全文
0 0
- Spring的applicationContent.xml配置详解
- Sping中根据applicationContent.xml获取spring容器
- SpringMVC入门配置web.config及applicationContent-mvc.xml
- spring aop的xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- spring-mybatis集成的xml配置详解,
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- spring的applicationContext.xml在web.xml中的配置详解
- 关于maven项目中测试获取在spring的applicationContent配置文件的问题
- Spring applicationContext.xml配置详解
- java程序中 获取本类的绝对路径(myeclipse,idea)
- using声明与using指令
- week1
- shell中的算术运算
- 【JPA】@OneToOne 一对一双向关联注解
- Spring的applicationContent.xml配置详解
- [Idea]DataBase通过Spring数据源配置文件生成数据源
- Python pass语句啥用处?
- 递归算法总结
- 网络架构
- -webkit-line-clamp 控制文字显示多行,多出部分显示省略号
- java foreach 获取对象的字段 List<company> lists
- 浏览器窗口的问题
- java发送电子邮件