Spring 无法打开类路径资源[application.properties],因为它不存在。Application.properties不可访问

Spring 无法打开类路径资源[application.properties],因为它不存在。Application.properties不可访问,spring,spring-boot,hibernate,spring-mvc,spring-data-jpa,Spring,Spring Boot,Hibernate,Spring Mvc,Spring Data Jpa,在我的SpringBoot应用程序中。不知何故,我的appication.properties文件在执行过程中未被读取。我又犯错误了 Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist 下面是我迄今为止所做的尝试,但我没有成功 1-在我的配置类中,我添加了以下内容: @PropertySo

在我的SpringBoot应用程序中。不知何故,我的appication.properties文件在执行过程中未被读取。我又犯错误了

Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
下面是我迄今为止所做的尝试,但我没有成功

1-在我的配置类中,我添加了以下内容:

@PropertySource(value="classpath:/application.properties")
public class StudentConfig {
2-在我的配置类中,我添加了这个

@Bean
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer location = new PropertySourcesPlaceholderConfigurer();
        location.setLocation(new ClassPathResource("application.properties"));
        location.setIgnoreUnresolvablePlaceholders(true);
        return location;
    }
3-我检查了我的属性文件是否在Resources文件夹中,但它仍然没有拾取该文件

下面是我的错误日志:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.student.main.StudentBackendApplication]; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at com.student.main.StudentBackendApplication.main(StudentBackendApplication.java:17) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_211]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_211]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_211]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.0.RELEASE.jar:2.3.0.RELEASE]
Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:99) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:73) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:59) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.core.io.support.ResourcePropertySource.<init>(ResourcePropertySource.java:67) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:462) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:279) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:206) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:174) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    ... 19 common frames omitted
org.springframework.beans.factory.BeanDefinitionStoreException:无法解析配置类[com.student.main.StudentBackendApplication];嵌套异常为java.io.FileNotFoundException:无法打开类路径资源[application.properties],因为它不存在
在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassPostProcessor.PostProcessBeandDefinitionRegistry(ConfigurationClassPostProcessor.java:236)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.support.postprocessorregistrationlegate.invokeBeanDefinitionRegistryPostProcessors(postprocessorregistrationlegate.java:280)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.support.postprocessorregistrationlegate.invokeBeanFactoryPostProcessors(postprocessorregistrationlegate.java:96)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
位于org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:315)[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
在com.student.main.StudentBackendApplication.main(StudentBackendApplication.java:17)[classes/:na]
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)~[na:1.8.0_211]
在sun.reflect.NativeMethodAccessorImpl.invoke(未知源)~[na:1.8.0_211]
在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源)~[na:1.8.0_211]
在java.lang.reflect.Method.invoke(未知源代码)~[na:1.8.0_211]
在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-2.3.0.RELEASE.jar:2.3.0.RELEASE]
原因:java.io.FileNotFoundException:无法打开类路径资源[application.properties],因为它不存在
在org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:99)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:73)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:59)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
位于org.springframework.core.io.support.ResourcePropertySource.(ResourcePropertySource.java:67)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.core.io.support.DefaultPropertySourceFactory.CreatePropertySourceSource(DefaultPropertySourceFactory.java:37)~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:462)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:279)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303)~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)~[spring-
<packaging>jar</packaging>