Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Frameworks
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Tim Cooke
paul wheaton
Sheriffs:
Paul Clapham
Liutauras Vilda
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Piet Souris
Himai Minh
Bartenders:
Forum:
Other Application Frameworks
Spring inject a list
kartik krishnan
Ranch Hand
Posts: 63
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I am a Spring newbie and I am trying to inject the list in the applicationContext
My applicationContext.xml
<bean id = "persons" class = "java.util.ArrayList" singleton="false" />
My code to access this bean:
public class SpringTest { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "/com/jbe/context/applicationContext-test.xml"); List/*<?>*/ persons= (List /*<?>*/) context.getBean("persons"); System.out.println(persons); } }
My stack trace;
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'persons' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(Ljava/lang/String;)Lorg/springframework/beans/factory/config/BeanDefinition;(DefaultListableBeanFactory.java:360) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(Ljava/lang/String;Z)Lorg/springframework/beans/factory/support/RootBeanDefinition;(AbstractBeanFactory.java:686) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ljava/lang/String;Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object;(AbstractBeanFactory.java:219) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ljava/lang/String;)Ljava/lang/Object;(AbstractBeanFactory.java:145) at org.springframework.context.support.AbstractApplicationContext.getBean(Ljava/lang/String;)Ljava/lang/Object;(AbstractApplicationContext.java:537) at com.jbe.context.SpringTest.main([Ljava/lang/String;)V(SpringTest.java:19)
Is there anything wrong in what I am doing? I would like to add more elements to collection. I am using spring 1.2 and Jdk 1.4
Christophe Verré
Sheriff
Posts: 14691
16
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
"/com/jbe/context/applicationContext-test.xml" : are you sure that "persons" is in this file ?
[My Blog]
All roads lead to JavaRanch
kartik krishnan
Ranch Hand
Posts: 63
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes, the bean is in the file
Christophe Verré
Sheriff
Posts: 14691
16
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And you have only one /com/jbe/context/applicationContext-test.xml in your classpath ? Also, could you post the exact content of your applicationContext-test.xml ?
[My Blog]
All roads lead to JavaRanch
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Exception in thread "main" org.springframework.beans.factory.BeanCreationException
org.springframework.beans.factory.BeanCreationException
CGLib error in "Before Advice" case
Exception due to Jaxb2Marshaller in spring
Spring 2.5 - Transaction example
More...