我在配置SpringAOP时遇到了一个问题。我创建了一个方面类,如下所示:
@Slf4j
@Aspect
@RequiredArgsConstructor
@Component
public class LoggingAspect {
private static final Logger logger = CommonLogger.getLogger(LoggingAspect.class);
private final ObjectMapper mapper;
private final JobExecutionService jobExecutionService;
}
然后我添加了一个配置文件:
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@RequiredArgsConstructor
public class AspectConfiguration {
private final ObjectMapper objectMapper;
private final JobExecutionService jobExecutionService;
@Bean
public LoggingAspect loggingAspect() {
return new LoggingAspect(objectMapper, jobExecutionService);
}
}
但当我启动应用程序时,我收到了以下错误:
通过构造函数实例化Bean失败;嵌套异常为org.springframework.beans.BeanInstanceException:未能实例化[org.springfframework.context.support.ClassPathXmlApplicationContext]:构造函数引发异常;嵌套异常为org.springframework.beans.factory.UnsatisfiedDependencyException:创建URL中定义的名称为"aspectConfiguration"的bean时出错:通过构造函数参数0表示的不满足依赖项;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的"com.fasterxml.jackson.databind.ObjectMapper"类型的合格bean:应至少有1个符合自动连线候选条件的bean。依赖项注释:{}
我已经将aspectjrt和aspectjweaver依赖项添加到pom.xml中。
春季版本为4.3.6
我不知道问题出在哪里。如有帮助,不胜感激。
添加类:
@Configuration
public class BeanConfig {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
}