spring简单配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 配置数据库链接 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/usermanager </value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>123456</value> </property> </bean> <!-- 配置SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" > <ref local="dataSource"/> </property> <!-- 配置Hibernate的属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <!-- 指定HIbernate映射文件的路径 --> <property name="mappingResources"> <list> <value>com/integration/entity/User.hbm.xml</value> </list> </property> </bean> <bean id="userDAO" class="com.integration.dao.UserDAOImpl" abstract="false" lazy-init="default" autowire="default"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="userService" class="com.integration.service.UserServiceImpl"> <property name="userDAO" ref="userDAO"></property> </bean> <bean id="userAction" class="com.integration.action.UserAction"> <property name="userService" ref="userService"></property> </bean> <bean id="loginAction" class="com.integration.action.LoginAction"> <property name="userService" ref="userService"></property> </bean> <bean id="userDeleteAction" class="com.integration.action.UserDeleteAction"> <property name="userService" ref="userService"></property> </bean> <bean id="userQueryAction" class="com.integration.action.UserQueryAction"> <property name="userService" ref="userService"></property> </bean> <bean id="userUpdateAction" class="com.integration.action.UserUpdateAction"> <property name="userService" ref="userService"></property> </bean> </beans>
1、配置datasource数据库链接;
2、配置sessionFactory 会话工厂;
3、配置各种bean类及bean类组合;
bean类组合一般是 配置DAO类----配置Service类,使用service类调用DAO类-----配置Action类,使用Action类调用Service类。
所有的bean都有ID,通过BeanId识别不同类的实体化;