欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring Cloud中遇到的Error creating bean with name 'hystrixCommandAspect' defined in class path resource

程序员文章站 2022-05-19 10:10:37
...

Error starting ApplicationContext. To display the auto-configuration report re-run your application with ‘debug’ enabled.
[2m2019-02-11 22:54:44.521[0;39m [31mERROR[0;39m [35m5060[0;39m [2m—[0;39m [2m[ main][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘hystrixCommandAspect’ defined in class path resource [org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/JoinPoint
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory1.getObject(AbstractBeanFactory.java:312) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) [springcontext4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) [springcontext4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124) [springboot1.5.19.RELEASE.jar:1.5.19.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)[springboot1.5.19.RELEASE.jar:1.5.19.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)[springboot1.5.19.RELEASE.jar:1.5.19.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:303)[springboot1.5.19.RELEASE.jar:1.5.19.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1118)[springboot1.5.19.RELEASE.jar:1.5.19.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1107)[springboot1.5.19.RELEASE.jar:1.5.19.RELEASE]atcom.ljr.crowdfunding.WebMemberApplication.main(WebMemberApplication.java:17)[classes/:na]Causedby:java.lang.NoClassDefFoundError:org/aspectj/lang/JoinPointatjava.lang.Class.getDeclaredMethods0(NativeMethod) [na:1.8.0172]atjava.lang.Class.privateGetDeclaredMethods(UnknownSource) [na:1.8.0172]atjava.lang.Class.getDeclaredMethods(UnknownSource) [na:1.8.0172]atorg.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:612) [springcore4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:488) [springcore4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:206) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:187) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:125) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:295) [springcontext4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:997) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) [springbeans4.3.22.RELEASE.jar:4.3.22.RELEASE]...15commonframesomittedCausedby:java.lang.ClassNotFoundException:org.aspectj.lang.JoinPointatjava.net.URLClassLoader.findClass(UnknownSource) [na:1.8.0172]atjava.lang.ClassLoader.loadClass(UnknownSource) [na:1.8.0172]atsun.misc.Launcher1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124) ~[spring-boot-1.5.19.RELEASE.jar:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.19.RELEASE.jar:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.19.RELEASE.jar:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.19.RELEASE.jar:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.19.RELEASE.jar:1.5.19.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.19.RELEASE.jar:1.5.19.RELEASE] at com.ljr.crowdfunding.WebMemberApplication.main(WebMemberApplication.java:17) [classes/:na] Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/JoinPoint at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_172] at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_172] at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_172] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:612) ~[spring-core-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:488) ~[spring-core-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:206) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:187) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:125) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:295) ~[spring-context-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:997) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-4.3.22.RELEASE.jar:4.3.22.RELEASE] ... 15 common frames omitted Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.JoinPoint at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_172] at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_172] at sun.misc.LauncherAppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_172]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_172]
… 26 common frames omitted

在引入Hystrix之后,运行项目报以上的错,一开始以为是依赖下载不完整的问题,删除本地依赖几次,重新安装之后还是没有解决,Spring Boot版本为1.5.19,
pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.19.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.ljr.springcloud</groupId>
	<artifactId>WebMember</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>MemberServiceClient</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>Edgware.SR5</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-openfeign</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>
				spring-cloud-starter-netflix-hystrix
			</artifactId>
		</dependency>
		
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

参考以下连接的回答:
https://*.com/questions/46448051/hystrix-fallback-method-gives-error
Spring Cloud中遇到的Error creating bean with name 'hystrixCommandAspect' defined in class path resource

引入以下依赖解决:

		<dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
相关标签: Spring Cloud