Hi,
I'm a beginner to spring. I'm getting a nullpointer exception while loading the bean class.
I loaded all the required spring jars.
Can any help me to solve this problem.
Project structure:
HellpSpring
-src
--com.tutorialspoint
---HelloWorld.java
---MainApp.java
--Beans-config.xml
Thank you!
Main file
-----------
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Beans-config.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
-----
HelloWorld
package com.tutorialspoint;
public class HelloWorld
{
private String message;
public void setMessage(String message)
{
this.message = message;
}
public void getMessage()
{
System.out.println("Your Message : " + message);
}
}
----------
Beans-config.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" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="helloWorld" class="com.tutorialspoint.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
</beans>
--------
Error log
Oct 05, 2012 11:48:38 AM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@35389244: startup date [Fri Oct 05 11:48:38 IST 2012]; root of context hierarchy
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.springframework.context.support.AbstractRefres hableApplicationContext.createBeanFactory(Abstract RefreshableApplicationContext.java:195)
at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:128)
at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:522)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:436)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
at com.tutorialspoint.MainApp.main(MainApp.java:10)
Caused by: java.lang.NullPointerException
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.<clinit>(DefaultListableBeanFac tory.java:104)
... 7 more


Reply With Quote
...
