applicationContext.xml文件的具体讲解
以我做的一个项目为例,对applicationContext.xml文件做简单的介绍: <!-- 文件的开头(一般为自动生成)--> <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!-- 数据库驱动 --> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"> </property> (mysql的驱动只需改变value的值为:“com.mysql.jdbc.Driver”) <!-- 数据库配置 --> <property name="url" value="jdbc:sqlserver://localhost:1433;databasename=our"> </property> (mysql的配置只需改变value的值为:“jdbc:mysql://localhost:3306/our”,其中也可对编码进行设置。 如:“jdbc:mysql://localhost:3306/our?useUnicode=true&characterEncoding=utf-8”) <property name="password" value="123"></property> </bean> <!-- 定义Hibernate的SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!--定义SessionFactory必须注入DataSource --> <ref bean="dataSource" /> </property> <!-- 定义Hibernate的SessionFactory。例如:方言和是否显示sql --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> <prop key="show_sql">true</prop> </props> </property> <!-- 配置映射文件 --> <property name="mappingResources"> <list> <value>org/bookstore/model/Book.hbm.xml</value> <value>org/bookstore/model/User.hbm.xml</value> <value>org/bookstore/model/Orders.hbm.xml</value> <value>org/bookstore/model/Orderitem.hbm.xml</value> <value>org/bookstore/model/Catalog.hbm.xml</value> <value>org/bookstore/model/Files.hbm.xml</value> </list> </property> </bean> <!-- 所有DAO全部注入 --> <bean id="userDAO" class="org.bookstore.dao.impl.UserDAO"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="catalogDAO" class="org.bookstore.dao.impl.CatalogDAO"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="bookDAO" class="org.bookstore.dao.impl.BookDAO"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="orderDAO" class="org.bookstore.dao.impl.OrderDAO"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- <bean id="imageDao" class="org.bookstore.dao.impl.ImageDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> --> <!-- 注入Service--> <bean id="userService" class="org.bookstore.service.impl.UserService"> <property name="userDAO"> <ref bean="userDAO" /> </property> </bean> <bean id="catalogService" class="org.bookstore.service.impl.CatalogService"> <property name="catalogDAO"> <ref bean="catalogDAO" /> </property> </bean> <bean id="bookService" class="org.bookstore.service.impl.BookService"> <property name="bookDAO"> <ref bean="bookDAO" /> </property> </bean> <bean id="orderService" class="org.bookstore.service.impl.OrderService"> <property name="orderDAO"> <ref bean="orderDAO" /> </property> </bean> <!-- 注入Action --> <bean id="userAction" class="org.bookstore.action.UserAction"> <property name="userService"> <ref bean="userService" /> </property> </bean> <bean id="bookAction" class="org.bookstore.action.BookAction"> <property name="catalogService"> <ref bean="catalogService" /> </property> <property name="bookService"> <ref bean="bookService" /> </property> </bean> <bean id="shoppingAction" class="org.bookstore.action.ShoppingAction"> <property name="bookService"> <ref bean="bookService" /> </property> <property name="orderService"> <ref bean="orderService"/> </property> </bean> </beans> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- BlazeDs Messaging service filtering
- 使用聚合函数及F/Q及分组查询
- SQlite数据库的C编程接口(一) 简介 ——《Using SQlite》
- PostgreSQL的问题:’now’不断返回相同的旧值
- Ajax ファイルダウンロード MVC(vb)
- configure: error: xml2-config not found. Please check y
- c# – Moq – 设置HttpResponse
- ruby-on-rails – RoR v3.2教程 – 坚持第9.2.2章
- Cocos2d 播放音乐
- oracle11g – 了解Oracle中的ORA_ROWSCN行为