引用 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的配置
使用myeclipse8.5搭建SSH后,将struts.xml和applicationContext.xml移动到别的地方,示例中为webroot下的config文件夹中,web.xml中需要做的修改示例。其中对于返回上一层方式不同的myeclipse可能不同,如有的用../...
spring spring mvc mybatis的整合配置
Spring2.0配置--> applicationContext.xml Hibernate3.2配置--> hibernate.cfg.xml JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的...
Spring2.0配置--> applicationContext.xml Hibernate3.2配置--> hibernate.cfg.xml JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的Action...
Spring2.0配置--> applicationContext.xml Hibernate3.2配置--> hibernate.cfg.xml JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的...
Spring2.0配置--> applicationContext.xml Hibernate3.2配置--> hibernate.cfg.xml JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的...
..........\src\applicationContext.xml ..........\...\cc\lz\action\action.java ..........\...\..\..\......\BaseAction.java ..........\...\..\..\dao\XiangmubiaoDAO.java ..........\...\..\..\persist...
JSPssh名片管理系统 是... 1、管理员账号:admin密码:admin 数据库配置文件applicationContext.xml 2、开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为mysql,使用java语言开发。 3、数据库名称jspsshmingpian.sql
2. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置; 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven ...
如博客中介绍 三、注意事项 1、管理员账号:admin 密码:admin 数据库配置文件applicationContext.xml 2、开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为Mysql5.0,使用java语言开发。 3、数据库文件名是...
如博客中介绍 三、注意事项 1、管理员账号:admin 密码:admin 数据库配置文件applicationContext.xml 2、开发环境为TOMCAT7.0,Myeclipse8.5开发 3、数据库文件名是jspsshtk.sql,系统名称sshtk 4、系统首页地址...
hibernate.cfg.xml 是hibernate配置信息和Spring的配置分开配置再通过classpath 导入给applicationContext.xml(这两个文件本身已经没使用到了) 项目现在hibernate配置信息都写在了applicationContext-common.xml中 ...
如博客中介绍 三、注意事项 1、管理员账号:admin 密码:admin 数据库配置文件applicationContext.xml 2、开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为Mysql5.0,使用java语言开发。 3、数据库文件名是...
SSH开发所需的包和配置文件,觉得可用,不要用myeclipse自动生成struts、hibernate、spring能力,自己添加,这个文件包括所需的包和web.xml,struts.xml,applicationContext.xml
如博客中介绍 三、注意事项 1、管理员账号:admin 密码:admin 数据库配置文件applicationContext.xml 2、开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为Mysql5.0,使用java语言开发。 3、数据库文件名是...
..............................................................................10 1.3.9MyEclipse 配置XML 提示:..............................................................................................
包含完整的代码(dao层有annotation和xml两种实现方式修改applicationContext.xml和hibernate.cfg.xml相应位置就可以切换),数据库ssh.sql文件,和所有的jar包,运行于eclips开发环境(myeclipse估计能用,没有测试...
如博客中介绍 三、注意事项 1、管理员账号:admin 密码:admin 数据库配置文件applicationContext.xml 2、开发环境为TOMCAT7.0,Myeclipse8.5开发,数据库为Mysql5.0,使用java语言开发。 3、数据库文件名是...