右键项目选择myeclipse然后add spring的jar包
1.先导入 Sping aop\core\p....core\p.....jdbc
2.导入Struts core\spring
3.导入Hibernate (3个都导入annontations\core\advanced)
其中第2步选spring配置文件
其中第3步选existing(已有的)配置文件选择spring
4.在web.xml文件中进行配置
<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>
5.在生成的applicationContext.xml文件当中修改一些配置文件:
前面的配置文件加上这三行:
还有下面这两个识别注解和扫描包的标签
<!-- 这个语句的作用是向spring容器注入为了能让系统识别相应的注解
如 @Resource、@Required、@Autowired、@PersistenceContext等注解
-->
<context:annotation-config></context:annotation-config>
<!-- 配置这句话的作用是扫描包,扫描包上的注解,
其实配置了context:componnent-scan 后就可以将 <context:annotion-config/>这个注解移除了
-->
<context:component-scan base-package="com.ssh"></context:component-scan>
6.在applicationContext.xml文件中注入 HibernateTemplate 这个类,并且在 系统对应的 DAO 层使用@Autowired引用这个 HibernateTemplate这个实体对象
applicationContext.xml文件中的配置
<!-- 注入Hibernate的模版类 -->
<bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
//DAO中引入这个template并且使用