Spring 依赖注入。无法打开类路径资源,因为它不存在
我对春天比较陌生,我还在学习 我有一个问题。这是我的项目结构 我在resources文件夹中创建了chuck-config.xml文件,我在其中声明了一个beanSpring 依赖注入。无法打开类路径资源,因为它不存在,spring,dependency-injection,Spring,Dependency Injection,我对春天比较陌生,我还在学习 我有一个问题。这是我的项目结构 我在resources文件夹中创建了chuck-config.xml文件,我在其中声明了一个bean <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc
<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>
但当我尝试运行应用程序时,出现了错误:
原因:java.io.FileNotFoundException:类路径资源
无法打开[chuck config.xml],因为它不存在于
org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
~[spring-core-5.2.8.释放。震击器:5.2.8.释放]位于
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:333)
~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]。。。23公共框架
省略
我做错了什么?为什么您的文件中不存在后缀.xml?
@SpringBootApplication
@ImportResource("classpath:chuck-config.xml")
public class JokeappApplication {
public static void main(String[] args) {
SpringApplication.run(JokeappApplication.class, args);
}
}