gpt4 book ai didi

java - BeanDefinitionStoreException : IOException parsing XML document from class path resource [applicationContext]

转载 作者:行者123 更新时间:2023-11-30 10:05:57 27 4
gpt4 key购买 nike

我正在尝试创建我的第一个 Spring 应用程序。它显示以下错误:

log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at com.spring1.FirstSpring1.main(FirstSpring1.java:20)
Caused by: java.io.FileNotFoundException: class path resource [applicationContext] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 4 more

GetterSetter.java

package com.spring1;

private String name;

public String getName()
{
return name;
}

public void setName(String name)
{
this.name=name;
}

public void displayInfo()
{
System.out.println("hello "+name);
}

FirstSpring1.java

package com.spring1;

public static void main(String[] args)
{
GetterSetter gt=new GetterSetter();
gt.setName("Google");
gt.displayInfo();

Resource resource = new ClassPathResource("applicationContext");
BeanFactory factory = new XmlBeanFactory(resource);
GetterSetter gt1 = (GetterSetter)factory.getBean("name1");
gt1.displayInfo();
}

XML 文件位于 src 文件夹中。

最佳答案

代替:

Resource resource = new ClassPathResource("applicationContext");

使用:

Resource resource = new ClassPathResource("applicationContext.xml");

关于java - BeanDefinitionStoreException : IOException parsing XML document from class path resource [applicationContext],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54967095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com