依赖注入。无法打开类路径资源,因为它不存在

时间:2020-09-02 10:01:07

标签: spring dependency-injection

我对Spring比较陌生,但我仍在学习。

我有一个问题。这是我的项目结构。

enter image description here

我在声明一个bean的资源文件夹中创建了chuck-config.xml文件

<beans xmlns = "http://www.springframework.org/schema/beans"
       xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation = "http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean name="chuckNorrisQuotes" class="guru.springframework.norris.chuck.ChuckNorrisQuotes"/>

</beans>

在JokeappApplication类中,我使用了@ImportResource注释,如下所示:

@SpringBootApplication
@ImportResource("classpath:chuck-config.xml")
public class JokeappApplication {

    public static void main(String[] args) {
        SpringApplication.run(JokeappApplication.class, args);
    }

}

但是当我尝试运行该应用程序时出现错误:

由于:java.io.FileNotFoundException:类路径资源 [chuck-config.xml]无法打开,因为它在以下位置不存在 org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) 〜[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:333) 〜[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] ... 23个常见帧 省略

我在做什么错了?

0 个答案:

没有答案