NutzCN Logo
问答 Spring整合Dao拦截器报错
发布于 2678天前 作者 哼哼的泰迪熊 2770 次浏览 复制 上一个帖子 下一个帖子
标签: spring dao

在之前的版本已经整合了Dao,代码如下:

<bean id="dao" class="org.nutz.dao.impl.NutDao">
		<property name="dataSource" ref="dataSource"/>
		<property name="runner" ref="daoRunner"/>
		<property name="sqlManager" ref="sqlManager"/>
	</bean>

现在使用1.r.58,想试试Dao拦截器,于是参照文档声明了类TestDaoInterceptor,将上面的配置改为:

<bean id="testInterceptor" class="com.sysbase.dao.interceptor.TestDaoInterceptor" />
	<bean id="dao" class="org.nutz.dao.impl.NutDao">
		<property name="dataSource" ref="dataSource"/>
		<property name="runner" ref="daoRunner"/>
		<property name="sqlManager" ref="sqlManager"/>
		<property name="interceptors">
			<list>
				<ref local="testInterceptor"></ref>
			</list>
		</property>
	</bean>

启动Tomcat后报错:

Invalid property 'interceptors' of bean class [org.nutz.dao.impl.NutDao]: Bean property 'interceptors' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

我看了看DaoSupport,是有setInterceptors,是我配置的有问题吗?求指点,谢谢。

3 回复

贴一下完整报错信息

我试了一下是可以的

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
	<bean id="nutDao" class="org.nutz.dao.impl.NutDao">
		<property name="dataSource" ref="dataSource" />
		<!-- 如果要使用Trans,移除springDaoRunner -->
		<property name="runner" ref="springDaoRunner" />
		<!-- 1.r.58新增 -->
		<property name="interceptors">
			<list>
				<bean class="org.nutz.integration.spring.SimpleDaoInterceptor"></bean>
				<value>log</value> <!-- 添加默认日志拦截器,一般放在最后就好了 -->
			</list>
		</property>
	</bean>
	<bean id="springDaoRunner" class="org.nutz.integration.spring.SpringDaoRunner"></bean>
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
		<property name="url" value="jdbc:h2:~/spring"/>
	</bean>
</beans>

看了回复后,我又去尝试了一下,最后解决了。
相同的配置我这里报错,后来发现idea输出的lib文件夹内有两个nutz,后来删了低版本的就好了。

添加回复
请先登陆
回到顶部