在春季项目中添加方面后不满意依赖异常



我在XML文件中有Spring配置的项目。我在下面添加了切入点的方面。

<aop:aspectj-autoproxy/>
<aop:config proxy-target-class="true">
<aop:aspect id="customAuditAspect" ref="customAudit">
<aop:pointcut id="customAuditPointcut"
expression="@target(lombok.NoArgsConstructor)"/>
<aop:before pointcut-ref="customAuditPointcut" method="customAuditUpdate"/>
</aop:aspect>
</aop:config>

这是一个豆子,上面提到的切入点指的是:

<bean id="customAudit" class="com.socha.modules.inspektr.aspect.AuditCustomUpdateAspect"/>

这是类:

@Slf4j
@NoArgsConstructor
public class AuditCustomUpdateAspect {
@Autowired
JdbcTemplate jdbcTemplate;*

public void customAuditUpdate() {
log.warn("here I am");
}
}

当我使用此功能部署 Web 应用程序时,它会通过以下方式抱怨:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'dataSourceAudit'
defined in ServletContext resource [/WEB-INF/spring-context/portlet-application-context.xml]:
Unsatisfied dependency expressed through constructor parameter 0:
Could not convert argument value of type [com.sun.proxy.$Proxy1719]
to required type [com.zaxxer.hikari.HikariConfig]:
Failed to convert value of type 'com.sun.proxy.$Proxy1719
implementing org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.cglib.proxy.Factory,com.zaxxer.hikari.HikariConfigMXBean,org.springframework.core.DecoratingProxy'
to required type 'com.zaxxer.hikari.HikariConfig';
nested exception is java.lang.IllegalStateException:
Cannot convert value of type 'com.sun.proxy.$Proxy1719
implementing org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.cglib.proxy.Factory,com.zaxxer.hikari.HikariConfigMXBean,org.springframework.core.DecoratingProxy'
to required type 'com.zaxxer.hikari.HikariConfig':
no matching editors or conversion strategy found

下面我将这个豆子与它的所有依赖豆子附加在一起:

<bean id="inspektrTransactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate"
p:transactionManager-ref="txManagerAudit" p:isolationLevelName="ISOLATION_READ_COMMITTED"
p:propagationBehaviorName="PROPAGATION_REQUIRED"/>
<bean id="auditHikariCPConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="auditHikariCP"/>
</bean>
<bean id="dataSourceAudit" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="auditHikariCPConfig"/>
</bean>

我或多或少地了解春季AOP是如何工作的。BeandataSourceAudit的第HikariDataSource类实现了一些接口,默认情况下它应用 JDK 代理。在上面的代码片段中,我正在尝试应用proxy-target-class=true,但仍然失败。我看到当我添加此设置时,实现的接口发生了一些变化 -org.springframework.cglib.proxy.Factory出现,但错误内容仍然相同。也许我最终未能在 bean 上应用此设置HikariDataSource这就是它不起作用的原因?

提前感谢您的任何提示

这个特殊的问题通过缩小建议类的范围来解决,正如R.G和Kriegaex所建议的那样。错误停止发生

谢谢

相关内容

最新更新