Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:46:09+00:00 2026-06-12T19:46:09+00:00

I have written a sample code to practise Spring Bean Injection using setter methods.

  • 0

I have written a sample code to practise Spring Bean Injection using setter methods.
But in my output I get a memory address instead of the value I need (in List Element list as 1st element).

I think this is due to some error in ref bean=”address1″ declaration.

Appreciate if you can please help me in correcing this error

This is the output I get

List Elements: [com.springtutorial.Address@1b6101e, Clash of Kings, Storm of Swords, Feast for Crows, Dance with Dragons]
Address :Winterfell

This is the Bean Class Code

<bean id="javaCollection" class="com.springtutorial.JavaCollection">
    <property name="addressList">
        <list>
            <ref bean="address1"/>
            <value>Clash of Kings</value>
            <value>Storm of Swords</value>
            <value>Feast for Crows</value>
            <value>Dance with Dragons</value>
        </list>
    </property>

</bean>

<bean id="address1" class="com.springtutorial.Address">
    <property name="address" value="Winterfell"/>
</bean>

This the Address Class Code

public class Address {

String address;

public String getAddress() {
    System.out.println("Address :"+address);
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

Java Collection class `public class JavaCollection {

List addressList;

public List getAddressList() {
    System.out.println("List Elements: " + addressList);
    return addressList;
}

public void setAddressList(List addressList) {
    this.addressList = addressList;
}

}

`

Main class is like this

public static void main(String[] args) {

    ApplicationContext ctx = new ClassPathXmlApplicationContext("Beans.xml");
    JavaCollection jc = (JavaCollection) ctx.getBean("javaCollection");
    Address obj = (Address) ctx.getBean("address1");

    jc.getAddressList();
    jc.getAddressSet();
    jc.getAddressMap();
    jc.getAddressProp();

    obj.getAddress();
}`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:46:10+00:00Added an answer on June 12, 2026 at 7:46 pm

    Thats because you missed to override the toString() method in Address, hence you are getting the default Output witch is the object identifier.

    public String toString() {
    
        String stringX = //build String
        return stringX;
    }
    

    Note: optionaly you can add the @Override – at the top of the methods.
    This has the following benefits:

    • The compiler checks that you are really overriding a method.
    • Other Programmers can easily see that you are overrding a method.

    Even so it may be a bit redundent for a commonenly overriden method such as toString().

    Other important methods that should commonly be overriden (but usually are forgotten) equals and toHashCode. It is important to override these for a variety of reasons explained here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sample code written for parsing xml file using javax.xml package. it uses
I have written grammar for a language (sample code below) //this is a procedure
I have written simple code to get content from xml file to php. $xml
I have this code sample (written by someone else) that parses the website, and
I have seen code (probably Apple's own sample code) written in such a way
I have written a code from the answer given here My sample code is
I have written a sample to insert txt file to MySql DB but i
i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
I have written a sample console application to test backgroundworker using one of the
I'have written a simple code, that gets accelerometer&orientation meter and display some graphics based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.