SpringCloud启动Provider微服务时出现java.io.FileNotFoundException异常

SpringCloud启动Provider微服务时出现java.io.FileNotFoundException异常

异常描述:

在这里org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.atguigu.spring.cloud.Provider]; nested exception is java.io.FileNotFoundException: class path resource [feign/hystrix/FallbackFactory.class] cannot be opened because it does not exist
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at com.atguigu.spring.cloud.Provider.main(Provider.java:23) [classes/:na]
Caused by: java.io.FileNotFoundException: class path resource [feign/hystrix/FallbackFactory.class] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:682) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:1008) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:375) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:323) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:191) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:295) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	... 13 common frames omitted插入代码片

我的第一反应是没有导入Feign对应的jar包,于是导了jar包

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

问题得到解决

但还有一个随之而来的疑问:
我的provider工程里面应该是没有需要引入feign的地方,以下是工程目录和对应的代码:

在这里插入图片描述

@EnableCircuitBreaker

@SpringBootApplication
public class Provider {
    public static void main(String[] args) {
        SpringApplication.run(Provider.class,args);
    }
}
@RestController
public class EmployeeHandler {

    private Logger logger = LoggerFactory.getLogger(EmployeeHandler.class);

    // HystrixCommand注解指定当前方法出问题时调用的备份方法(使用fallbackMethod属性指定)
    @HystrixCommand(fallbackMethod = "getEmpWithCircuitBreakerBackUp")
    @RequestMapping("/provider/get/emp/with/circuit/breaker")
    public ResultEntity<Employee> getEmpWithCircuitBreaker(@RequestParam("signal") String signal) throws Exception{

        if("quick-bang".equals(signal)){
            throw new RuntimeException();
        }

        if("slow-bang".equals(signal)){
            Thread.sleep(3000);
        }

        return ResultEntity.successWithData(new Employee(666,"empName666",66.66));
    }

    public ResultEntity<Employee> getEmpWithCircuitBreakerBackUp(@RequestParam("signal") String signal){

        String message = "方法执行出现问题,执行断路 signal="+signal;

        return ResultEntity.failed(message);
    }
}

yml配置

server:
  port: 1000

eureka:
  client:
    service-url:    # 配置当前微服务作为 Eureka 客户端访问 Eureka 服务器端时使用的地址
      defaultZone: http://localhost:5000/eureka



spring:
  application:
    name: atguigu-provider  # 指定当前微服务名称,以便将来通过微服务名称调用微服务时能够找到

疑问暂时未得到解决,在此进行记录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
java.io.FileNotFoundExceptionJava中的一个异常类,表示无法找到指定的文件或目录。它通常在文件操作中出现,当尝试打开或读取一个不存在的文件会抛出该异常。 引用中的错误信息显示了一个java.io.FileNotFoundException异常的示例。该异常的原因是拒绝访问,可能是由于文件不存在或者没有足够的权限来访问该文件。 引用提到了可能导致java.io.FileNotFoundException异常的两个原因。第一个原因是文件不存在,即指定的文件路径不正确或文件被删除。第二个原因是权限被拒绝,即当前用户没有足够的权限来访问该文件。 如果你遇到java.io.FileNotFoundException异常,你可以按照以下步骤来解决问题: 1. 确保文件路径正确:检查文件路径是否正确,包括文件名和文件所在的目录路径。 2. 检查文件是否存在:确认文件是否存在于指定的路径中。你可以使用文件对象的exists()方法来检查文件是否存在。 3. 检查文件权限:如果文件存在但仍然抛出java.io.FileNotFoundException异常,那么可能是由于权限问题。你可以检查当前用户是否具有足够的权限来访问该文件。 以下是一个示例代码,演示了如何处理java.io.FileNotFoundException异常: ```java import java.io.File; import java.io.FileNotFoundException; public class FileExample { public static void main(String[] args) { String filePath = "path/to/your/file.txt"; File file = new File(filePath); try { // 尝试打开文件 Scanner scanner = new Scanner(file); // 读取文件内容 while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } // 关闭文件 scanner.close(); } catch (FileNotFoundException e) { // 处理文件不存在的情况 System.out.println("文件不存在:" + e.getMessage()); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值