加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

依赖注入 抽象类

发布时间:2020-12-13 20:22:39 所属栏目:百科 来源:网络整理
导读:Spring配置Bean如下: bean id="Privilege" parent="txProxyTemplate" property name="target" bean class="com.langtoo.privilege.PrivilegeImpl" property name="userDao" ref="SysUserDao" / /bean /property /bean txProxyTemplate 作用是继承 其他sprin

Spring配置Bean如下:

<bean id="Privilege" parent="txProxyTemplate">
<property name="target">
<bean class="com.langtoo.privilege.PrivilegeImpl">
<property name="userDao" ref="SysUserDao" />
</bean>
</property>
</bean>

txProxyTemplate 作用是继承 其他spring.xml中声明式事务的,这里关键注意的是 id ="Privilege" 和class = "com.langtoo.privilege.PrivilegeImpl"

下面采用 autowire=byName 方式来介绍经验,如果PrivilegeImpl.java 是 接口的实现类,那么就不会出错。

如果PrivilegeImpl.java 是 抽象类的实现类,编译时报异常:

Error creating bean with name 'Privilege' defined in class path resource [spring/spring-services-privilege.xml]: Invocation of init method failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.

那么解决办法是:在ClassPath下添加cglib-2.1_3.jar包,我添加的是2.1_3的版本。

之后如果编译时继续报异常:

org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'Privilege' defined in class path resource [spring/spring-services-privilege.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type

那么解决办法是:在ClassPath下添加asm-1.5.3.jar包,我添加的是1.5.3的版本。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读