Spring ClassPathXmlApplicationContext NullPointerException [英] Spring ClassPathXmlApplicationContext NullPointerException

查看:38
本文介绍了Spring ClassPathXmlApplicationContext NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用弹簧.xml 文件在 src 下.我已经搜索过,但找不到问题所在.好像找不到xml文件.

Trying to use spring. The xml file is under src. I've searched and cannot find the problem. Seems it cant find the xml file.

我收到以下错误:

    Exception in thread "main" java.lang.ExceptionInInitializerError
at org.springframework.core.env.AbstractEnvironment.suppressGetenvAccess(AbstractEnvironment.java:406)
at org.springframework.core.env.AbstractEnvironment.getSystemEnvironment(AbstractEnvironment.java:368)
at org.springframework.core.env.StandardEnvironment.customizePropertySources(StandardEnvironment.java:79)
at org.springframework.core.env.AbstractEnvironment.<init>(AbstractEnvironment.java:124)
at org.springframework.core.env.StandardEnvironment.<init>(StandardEnvironment.java:54)
at org.springframework.context.support.AbstractApplicationContext.createEnvironment(AbstractApplicationContext.java:444)
at org.springframework.context.support.AbstractApplicationContext.getEnvironment(AbstractApplicationContext.java:283)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.resolvePath(AbstractRefreshableConfigApplicationContext.java:122)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.setConfigLocations(AbstractRefreshableConfigApplicationContext.java:80)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:137)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.hancock.javabrains.DrawingApp.main(DrawingApp.java:13)
Caused by: java.lang.NullPointerException
at org.springframework.core.SpringProperties.<clinit>(SpringProperties.java:58)
... 12 more

这是导致错误的行(通过将 Beans.xml 更改为错误的名称,我仍然遇到相同的错误):

This is the line causing an error (By changing Beans.xml to an erroneous name I still get same error):

ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

xml(Beans.xml):

The xml (Beans.xml):

<?xml version="1.0" encoding="UTF-8"?>

<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-4.0.xsd">

<bean id="helloWorld" class="org.hancock.javabrains.HelloWorld">
   <property name="message" value="Hello World!"/>
</bean>

</beans>

推荐答案

提供完整文件路径试试这个

Try this by giving the full file path

ApplicationContext ctx = new FileSystemXmlApplicationContext("Beans.xml");

这篇关于Spring ClassPathXmlApplicationContext NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆