Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
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
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
Spring
Spring with Generics Collection
deepak carter
Ranch Hand
Posts: 165
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi All,
I have written a small program for list using spring framework.This is what i have written
Context file
<?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-3.0.xsd"> <bean id="collectionspring" class="org.springtest.SpringCollection"> <property name="address1"> <list> <ref bean="address12" /> <value>dehradun</value> <value>Uttarakhand</value> </list> </property> </bean> <bean id="address12" class ="org.springtest.Address"> <property name="address1" value="Bangalore" /> </bean> </beans>
two files are there for address setting
package org.springtest; public class Address { private String address1; public String getAddress1() { return address1; } public void setAddress1(String address1) { this.address1 = address1; } }
package org.springtest; import java.util.List; public class SpringCollection { List<Address> address1; public List<Address> getAddress1() { return address1; } public void setAddress1(List<Address> address1) { this.address1 = address1; } }
and my MAIN CLASS..
package org.springtest; import java.util.Iterator; import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringCollectionTest { public static void main(String[] args) { List i; ApplicationContext context=new ClassPathXmlApplicationContext("bean.xml"); SpringCollection sc=(SpringCollection)context.getBean("collectionspring"); System.out.println(sc.getAddress1()); } }
However its throwing an error
Can anyone help me in this regard
Mark Spritzler
ranger
Posts: 17347
11
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes, you are trying to add two Strings to a Collection that only takes Address objects. This would throw an exception in
Java
without Spring.
<value>someString</value>
Why would you expect otherwise?
Mark
Perfect World Programming, LLC
-
iOS Apps
How to Ask Questions the Smart Way FAQ
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Spring,JUnit, Hibernate and persistence db but not insert
tell me what is this error?
getting same result in AutoWiring byType and byName
@Autowired problem
Junit + ContextConfiguration
More...