Spring的applicationContext.xml文件
想必用过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 >
<!-- 数据库驱动,我这里使用的是Mysql数据库
-->
<property
>
<value>com.mysql.jdbc.Driver</value>
</property>
<!--
数据库地址,这里也要注意一下编码,不然乱码可是很郁闷的哦! -->
<property
>
<value>
jdbc:mysql://localhost:3306/tie?useUnicode=true&characterEncoding=utf-8
</value>
</property>
<!-- 数据库的用户名
-->
<property
>
<value>root</value>
</property>
<!--
数据库的密码 -->
<property
>
<value>123</value>
</property>
</bean>
<!--
把数据源注入给Session工厂 -->
<bean
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property
>
<ref bean="dataSource" />
</property>
<!--
配置映射文件 -->
<property
>
<list>
<value>com/alonely/vo/User.hbm.xml</value>
</list>
</property>
</bean>
<!--
把Session工厂注入给hibernateTemplate -->
<!--
解释一下hibernateTemplate:hibernateTemplate提供了很多方便的方法,在执行时自动建立 HibernateCallback
对象,例如:load()、get()、save、delete()等方法。 -->
<bean
class="org.springframework.orm.hibernate3.HibernateTemplate">
<constructor-arg>
<ref
local="sessionFactory"
/>
</constructor-arg>
</bean>
<!--
把DAO注入给Session工厂 -->
<bean >
<property >
<ref
bean="sessionFactory" />
</property>
</bean>
<!--
把Service注入给DAO -->
<bean >
<property >
<ref
local="userDAO" />
</property>
</bean>
<!--
把Action注入给Service -->
<bean >
<property >
<ref
bean="userService"
/>
</property>
</bean>
</beans>
以上Spring的applicationContext.xml文件我是用的SSH架构,如果您用Spring的MVC架构,其原理也是一样的。
分享到:
相关推荐
Spring applicationContext.xml常见部分属性的使用备注
spring4的“所有jar包”+applicationContext.xml+web.xml====全套
包含applicationContext.xml、db.properties、log4j.properties、spring-mvc.xml文件,方便搭建,省去写代码。。
详解Spring的applicationContext.xml文件代码:
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件4
Spring ApplicationContext.xml配置的12个技巧演示教学.pdf
本篇文章主要介绍了详解spring applicationContext.xml 配置文件 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
spring定时任务必须的包和spring配置说明
applicationContext.xml+hiberniate属性+Session属性+自动代理+拦截器!!!! 上传的限制去除了jar包!
NULL 博文链接:https://mutourenoo.iteye.com/blog/1156865
spring+jpa的applicationContext.xml配置
Spring[applicationContext.xml]灵活性代理
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件6
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件1
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件3
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件5
spring约束文件头文件ApplicationContext.xml的头文件