Spring框架应用时,报"tx:advice" is not bound的错误

今天做一个S2SH项目的练习,配置SpringContext.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" 
       <span style="color:#FF0000;"> xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"</span>
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   <span style="color:#FF0000;">     http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"></span>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="WEB-INF/conf/hibernate.cfg.xml">
		</property>
	</bean>

	<bean id="txManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<tx:advice id="tx" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="save*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="remove*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="delete*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="update*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="register*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<aop:config>
		<aop:pointcut id="trAllMethod"
			<span style="color:#009900;">expression="execution(* com.hsExt.service.*.*(..))" /></span>
		<aop:advisor advice-ref="tx" pointcut-ref="trAllMethod" />
	</aop:config>
</beans>


问题原因:Myeclipse不能识别<tx:advice/>标签,在定义申请AOP的时候,不能加载schema,在<beans >里加入如上述代码所示的代码片段,Myeclipse就能够识别<tx:advice/>,<aop:config/>;

代码片段中,几个通配符的含义:

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

所以(* com.hsExt.service.*.*(..))匹配:包com.hsExt.service下的任意class的具有任意返回值类型、任意数目参数和任意名称的方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个问题表示在你的代码中没有定义或导入“android”命名空间。需要在代码中加上“xmlns:android=”http://schemas.android.com/apk/res/android””来绑定该命名空间。 ### 回答2: "namespace android is not bound"是Android程序开发中常见的错误信息之一。它意味着在XML文件中使用了Android命名空间,但它没有正确地绑定。命名空间是定义一组标签的方法,以便在同一个XML文档中使用不同的标签名称而不会引起冲突。而Android命名空间是指用于定义Android组件如activity、fragment、service等的一组标签。当这个命名空间没有正确地绑定,将无法使用这些标签或属性。 通常,出现命名空间未绑定的错误有以下几个原因: 1.忘记在XML文件中声明命名空间。在XML文件中使用Android命名空间,应该在文档的根元素中声明它。例如:xmlns:android="http://schemas.android.com/apk/res/android"。这将定义一个名为“android”的命名空间,使得使用这个命名空间下的标签和属性能够被识别。 2.在XML文件中使用了非法的命名空间。在Android中,只有"android"命名空间是合法的,其他的命名空间无法识别。 3.编辑器或IDE错误地识别了命名空间。在某些情况下,IDE或编辑器可能不能正确地识别命名空间。这种情况下,我们应该检查所使用的命名空间是否含有输入错误。 为了避免出现这个错误,我们应该总是规范地编写XML文件,确保所有使用的Android组件的命名空间正确绑定。如果出现这个错误,我们可以检查上述三个原因并进行纠正。 ### 回答3: namespace android is not bound 是一个 Android Studio 编译器错误的提示信息,表示在当前布局文件中使用了 android 命名空间的控件或属性,但是编译器却找不到该命名空间的定义。 解决这个问题可以从以下几个方面入手: 1. 确认当前项目的编译版本是否正确,若当前项目的编译版本与所使用的控件或属性版本不一致,则可能出现该错误提示。可以在项目 build.gradle 文件中修改 targetSdkVersion 和 compileSdkVersion 的版本号。 2. 确认 XML 文件中是否存在语法错误或者拼写错误,特别是检查标签闭合是否正确。语法错误和拼写错误都可能导致编译器无法识别 android 命名空间。 3. 检查当前布局文件的根布局是否包含了有效的命名空间定义,一般情况下 Android XML 文件的根布局应该包含这样的命名空间定义: xmlns:android="http://schemas.android.com/apk/res/android" 若缺少该命名空间定义,也会导致出现该错误提示。 4. 确认当前刻是否有网络连接可用,如果没有网络连接,有可能导致编译器无法下载 Android 的官方命名空间定义文件。 总的来说,出现 namespace android is not bound错误提示一般是编译器找不到正确的命名空间定义所致,解决方法多为检查代码语法,确认编译版本一致,检查命名空间是否定义正确等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值