[TOC]
AOP IOC 整合
spring 整合Hibernate
步骤
- 导入jars 相关的spring -orm
- 由spring来创建sessionFactory
<!-- 创建sessionFcatory对象-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
- 创建新的dao实现类 UserDaoImpHibernateDaoSupport 继承HibernateDaoSupport
public class UserDaoImpHibernateDaoSupport extends HibernateDaoSupport
implements IUserDaoHibernate {
}
- beans 里加上自动装备 default-autowrie="byName
<beans
default-autowire="byName"
>
IOC 整合
spring整合steuts2
环境搭建
jars
struts2-spring- plugin-2.3.8.jar
web.xml 配置spring初始化; 加监听器
<!-- spring初始化 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
- 配置常量struts.objectFactory; struts.xml
<constant name="struts.objectFactory" value="spring"></constant>
实现业务请求
- 创建bean @Controller("userAction")
@Controller("userAction")
public class UserAction extends ActionSupport implements ModelDriven<User>{
}
- userAction 依赖注入
@Autowired
private IUserviceHibernate usb;
- 增加扫描action包
<context:component-scan base-package="com.wxb.dao,com.wxb.service.,com.wxb.aop,com.wxb.action">
</context:component-scan>