`

[转]引用 MyEclipse中applicationContext.xml配置及常见问题

    博客分类:
  • ssh
 
阅读更多
引用 MyEclipse中applicationContext.xml配置及常见问题
2011-05-21 12:21

 

SHH(Struts1.2 + Spring2.0 + hibernate3.1)结合的javaWeb工程的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"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

 <!-- 会话工厂 -->
 <bean id="SessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation" value="classpath:hibernate.cfg.xml">
  </property>
 </bean>
 <!-- 数据层 -->
 <bean id="dao" class="dao.DaoSupportHibernate3Impl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <!-- 业务层 -->
 <bean id="city" class="service.CityServiceImpl">
  <property name="support" ref="dao"></property>
 </bean>
 
 <!-- 事务管理 -->
 <bean id="myHibTransactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>
 
 <!-- 事务通知 -->
 <tx:advice id="txAdvice" transaction-manager="myHibTransactionManager">
  <tx:attributes>
   <tx:method name="*" propagation="REQUIRED" />
  </tx:attributes>
 </tx:advice>
 
 <!-- 添加事务 -->
 <aop:config>
  <aop:pointcut id="bizMethods" expression="execution(* com.service.*.*(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
 </aop:config>
</beans>

以上是整个文件的具体配置,Spring使用 <tx:advice>和 <aop:config> 用来配置事务,具体如何配置你可以参考Spring文档。

(* com.service.*.*(..))中几个通配符的含义:

第一个 * —— 通配 任意返回值类型
第二个 * —— 通配 包com.service下的任意class
第三个 * —— 通配 包com.service下的任意class的任意方法
第四个 .. —— 通配 方法可以有0个或多个参数

 

此文件会时常出现 Class"org.springframework.orm.hibernate3.LocalSessionFactoryBean"not found和The prefix "tx" for element "tx:advice" is not bound两个问题。

第一个问题解决办法:

出现该问题是在为工程添加Spring包的时候没有添加Spring 2.0 Persistence Core Libraries一项,导致缺少Spring的spring-hibernate3.jar包。

第二个问题解决办法:

出现该问题是定义申明AOP的时候,没有加载schema,只需要在<beans>中要加入“xmlns:aop”的命名申明,并在“xsi:schemaLocation”中指定aop配置的schema的地址。
配置文件如下:
<?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:aop="http://www.springframework.org/schema/aop "
xmlns:tx="http://www.springframework.org/schema/tx "
xsi:schemaLocation="http://www.springframework.org/schema/beans
                     http://www.springframework.org/schema/beans/spring-beans.xsd
                     http://www.springframework.org/schema/tx
                     http://www.springframework.org/schema/tx/spring-tx.xsd
                     http://www.springframework.org/schema/aop
                     http://www.springframework.org/schema/aop/spring-aop.xsd ">


问题到此解决完。

 

分享到:
评论

相关推荐

    struts.xml和applicationContext.xml、web.xml的配置

    在Java Web开发中,`struts.xml`, `applicationContext.xml` 和 `web.xml` 是三个至关重要的配置文件,它们各自负责不同的职责,并协同工作来构建一个完整的应用框架。以下是关于这三个配置文件的详细说明。 首先,...

    struts、applicationContext配置文件移动后web.xml配置示例

    使用myeclipse8.5搭建SSH后,将struts.xml和applicationContext.xml移动到别的地方,示例中为webroot下的config文件夹中,web.xml中需要做的修改示例。其中对于返回上一层方式不同的myeclipse可能不同,如有的用../...

    Struts2.1、Spring3.0、Hibernate3.3整合与S2SH的XML文件拆分

    这通常在Spring的配置文件(如`applicationContext.xml`)中完成,通过定义数据源(DataSource)。在MyEclipse中,可以使用Database Explorer工具来创建数据库连接,输入相应的Driver name、Connection URL、User ...

    myeclipse配置ssh.docx

    在src目录下创建applicationContext.xml文件,配置Bean的定义和依赖注入。Spring与Hibernate的整合通常通过SessionFactoryBean进行,配置SessionFactory并管理事务。 在配置过程中,可能会遇到一些问题,例如由于...

    myeclipse框架搭建步骤.pdf

    在添加 Hibernate 特性后,MyEclipse 会生成一个 applicationContext.xml 配置文件,该文件中将包含 Hibernate 的配置信息。 本文详细介绍了 MyEclipse 框架搭建步骤,包括创建项目、添加 Spring 和 Hibernate 框架...

    Myeclipse8.5SSH配置

    在`applicationContext.xml`中,这是Spring的配置文件,它定义了数据源、SessionFactory以及Spring与Hibernate的整合。这里,我们看到一个名为`dataSource`的bean,用于配置数据库连接: ```xml ...

    Spring在MyEclipse中的配置

    - `applicationContext.xml`:Spring的核心配置文件,其中包含了默认的XML文件声明和DTD引用。 #### 四、总结 通过上述步骤,可以在MyEclipse中轻松地为Java Web项目添加Spring支持。这种方式不仅大大简化了配置...

    MyEclipse配置.doc

    - 完成配置后,applicationContext.xml文件会被创建,但内容为空,已经引入了Spring的Schema。 3. **配置Hibernate**: - 类似地,通过"MyEclipse -&gt; Project Capabilities -&gt; Add Hibernate Capabilities"菜单...

    MyEclipse中SSH配置文件提示插件

    标题中的"MyEclipse中SSH配置文件提示插件"指的是在MyEclipse集成开发环境中,用于增强对SSH(Spring、Struts、Hibernate)架构配置文件的智能提示和代码辅助功能的插件。SSH是Java Web开发中常用的三大框架,Spring...

    myeclipse框架搭建步骤.doc

    4. 配置数据源:在`applicationContext.xml`中配置数据源,并与SessionFactory关联。 ### 7. 整合与测试 现在,SSH框架已经基本搭建完成。你可以开始编写业务逻辑,配置Action,创建Service,注入DAO,使用...

    在myeclipse自动提示spring的配置信息

    MyEclipse的Spring插件还提供了XML格式化和配置文件验证的功能,确保配置文件符合Spring的规范,避免因为XML错误导致的启动问题。 9. **Spring Roo集成** 如果使用Spring Roo,MyEclipse的集成可以进一步提升开发...

    myeclipse实现用户登录的详细教程

    本教程详细介绍了使用myeclipse实现用户登录系统的步骤,包括创建Web项目、添加JUnit库、添加SpringCapabilities、配置web.xml、配置applicationContext.xml、配置controller-Servlet.xml、创建index.jsp、创建User...

    图文教程MyEclipse配置struts+hibernate+spring.doc

    在本文档中,我们可以看到spring的配置过程,包括添加spring需要的文件、配置applicationContext.xml文件等。 4.三框架的整合 本文档的主要内容是讲述如何将struts、hibernate和spring三个框架整合在一起,以实现...

    myeclipse的ssm框架例子

    在MyEclipse中,我们可以通过新建Spring Project来创建一个基础的Spring环境,并添加对应的配置文件如`applicationContext.xml`,来定义和管理Bean。 其次,Struts2作为表现层框架,处理HTTP请求并将其转发到相应的...

    初学者SSH框架在MyEclipse里搭建

    9. **配置Hibernate**:在applicationContext.xml中配置数据源、SessionFactory,设置数据库方言等属性,使Spring管理Hibernate SessionFactory。 10. **反向生成实体类和配置文件**:使用Hibernate的反向工程工具...

    J2EE三大框架SSH在MyEclipse工具中整合配置流程

    ### J2EE三大框架SSH在MyEclipse工具中的整合配置流程 #### 一、概述 在Java企业级应用开发中,SSH(Struts + Spring + Hibernate)是经典的三层架构组合,其中Struts负责表现层,Spring负责业务逻辑层,Hibernate...

    SSH2的myeclipse中的配置

    SSH2在MyEclipse中的配置是一项关键任务,对于开发基于Spring、Struts和Hibernate这三大框架的Java Web应用至关重要。SSH2(Spring、Struts2和Hibernate2)是这些技术的升级版本,提供了更强大的功能和更好的性能。...

    使用MyEclipse生成SSH项目的步骤.docx

    在IT行业中,SSH(Struts2、Spring、Hibernate)是一个常见的Java Web开发框架组合,用于构建高效、可扩展的企业级应用程序。MyEclipse是一款强大的集成开发环境,支持快速创建SSH项目。以下是使用MyEclipse生成SSH...

    MyEclipse整合ssh三大框架环境搭载用户注册源码下载

    2. 配置Hibernate的实体类和数据源,以及在web.xml中配置Hibernate的SessionFactory。 【整合过程】 1. 将Hibernate的配置移出applicationContext.xml,放入单独的文件,以便于管理。 2. 在Spring配置文件中,配置...

Global site tag (gtag.js) - Google Analytics