Hi,
I have a working Spring Application (MVC) and I want to initialise a Map property, but I am getting BeanCreationException. For example:
My servlet-content.xml file includes the following entry:Code:Error creating bean with name 'myprops2' defined in ServletContext resource [/WEB-INF/servlet-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ilt.myport.MySpecial]: Constructor threw exception; nested exception is java.lang.NullPointerException
My class' snippet is:Code:<beans:bean id="myprops2" class="com.ilt.myport.MySpecial"> <beans:property name="myprops2"> <beans:map> <beans:entry key="myFieldType" value="Special X Key" /> <beans:entry key="myFieldActive" value="true" /> </beans:map> </beans:property> </beans:bean>
And of course, my classes are on the classpath as the MVC configuration works fine.Code:// declaration private Map<String,String> myprops2; // setter for bean instantiation public void setMyprops2(Map<String, String> myprops2) { this.myprops2 = myprops2; }
Also, I would like to know if it is possible to initialise static collections, that is, intead of the above declaration, if I had:
...would that be fine with the same bean configuration? If not, what is the work around?Code:private static Map<String,String> myprops2; public static void setMyprops(Map<String, String> myprops) { MySpecial.myprops = myprops; }


Reply With Quote
