SSH2集成:Spring3.0+Struts2.2+Hibernate3.3 beans.xml配置详解

需积分: 0 1 下载量 114 浏览量 更新于2024-08-18 收藏 782KB PPT 举报
本文档主要介绍了如何在Spring 3.0版本与Struts 2.2、Hibernate 3.3框架集成的项目中,使用beans.xml文件进行配置。在Struts2.2应用中,Spring提供了强大的依赖注入支持,而Hibernate则用于持久化层的操作。 首先,我们关注于Spring的配置部分。在`<bean>`标签内定义了一个名为`sessionFactory`的bean,这是Spring ORM的一部分,用于创建Hibernate SessionFactory对象。这个对象是Hibernate与应用程序之间的重要桥梁,它负责管理数据库连接和映射关系。配置项`<property name="dataSource">`指定了数据源,这通常是一个已经配置好的Spring数据源bean,如JDBC或JNDI数据源。`<property name="mappingResources">`用于指定Hibernate的映射文件,这里是`com/cn/Stu.hbm.xml`,这是定义了实体类与数据库表之间映射关系的XML文件。 `<property name="hibernateProperties">`包含了Hibernate的配置参数,例如`<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>`,这表明该项目使用的数据库是MySQL,`MySQLDialect`是相应的方言,确保了数据库特定的功能正确工作。 接下来是SSH2集成的介绍,SSH2指的是Struts、Spring和Hibernate的组合。文档列出了三个框架所需的主要JAR包及其作用: 1. Struts2.1.6:提供核心类库、UI标签模板(Freemarker)、日志支持(commons-logging)、对象图导航语言(OGNL)、xwork类库以及文件上传功能相关的jar包。 2. Hibernate3.3.2:包含核心类库、解析HQL所需的ANTLR、集合框架、XML解析库、字节码操作工具(javassist)、JTA支持以及测试和注解相关的jar包。 3. Spring2.5.6:Spring框架的核心文件,还包括了一些Spring与Hibernate集成所必需的注解库。 该文档详细说明了如何在Spring中配置Hibernate的SessionFactory,以及如何将这三个流行框架整合在一起以实现企业级应用的开发。这对于理解和配置基于Spring、Struts和Hibernate的Web应用项目至关重要,特别是对于那些希望使用注解方式简化配置和提高代码可读性的开发者来说。

我用Spring5的aop应用时报这个错误Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\ecliple\web5\WEB-INF\applicationContext.xml]; nested exception is java.nio.file.NoSuchFileException: WEB-INF\applicationContext.xml,他说我的applicationContext.xml文件不存在,可是我明明有这个文件,另外我的web.xml需要更改吗<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <context-param> <param-name>contextConfigLocation </param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <display-name>Struts2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>

2023-05-30 上传