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

  • SEARCH
  • Home
  • 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 7059725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:16:01+00:00 2026-05-28T04:16:01+00:00

I am trying to achieve lookup method injection using a simple example. But, seems

  • 0

I am trying to achieve lookup method injection using a simple example. But, seems to fail in getting the bean injected via the method.

I have a simple bean namely; DemoBean as below:

public class DemoBean {

    private String message;

    public DemoBean() {

    }

    public DemoBean(String message) {
        this.message = message;
    }

    // Getter and Setter methods

    @Override
    public String toString() {
        return "DemoBean{" +
                "message='" + message + '\'' +
                '}';
    }
}

I am trying to inject DemoBean into another bean namely; PropertyBean:

public abstract class PropertyBean {

    private DemoBean bean;
    private String message;
    // other members...

    public PropertyBean(String message) {
        this.message = message;
    }

    // Getter and Setter methods...

    // Method for lookup injection
    protected abstract DemoBean createBean();

    @Override
    public String toString() {
        return "PropertyBean{" +
                "bean=" + bean.toString() +
                ", message='" + message + '\'' +
                ", number=" + number +
                '}';
    }
}

Noe, there is my beans configuration:

<bean id="demobean" class="aro.discoverspring.beans.DemoBean" scope="prototype">
<property name="message" value="The Default Message!!!" />
</bean>

<bean id="propertybean" class="aro.discoverspring.beans.PropertyBean">
<constructor-arg name="message" value="A message in PropertyBean"/>
<lookup-method name="createBean" bean="demobean" />
</bean>

When try to create an instance of PropertyBean. I am able to do so. But when I do the following.. I get null pointer exception on the DemoBean property (Because the bean is not getting injected!!)

PropertyBean pb = (PropertyBean) ctx.getBean("propertybean");       
System.out.println(pb.toString());

What am I doing wrong? Did I miss anything or am I overlooking something silly there!?
Spring 3.0 reference (section 3.4.6.1) seems to be doing the same.

  • 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-05-28T04:16:02+00:00Added an answer on May 28, 2026 at 4:16 am

    bean property shouldn’t be injected. As I understand spring implements createBean method for you, so when you call pb.createBean() it should return instance of DemoBean. But you don’t assign anything to bean property in ProperyBean so there is no way for it to be not null.

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

Sidebar

Related Questions

Im trying to achieve an output like this {status:ok,0:{id:11,title:digg,url:http://www.digg.com}} but instead i am getting
I'm trying to achieve something apparently simple but I couldn't find any answer, neither
What I'm trying to achieve must be simple but I just can't get it
I am trying to achieve peer to peer communication using winsock but gethostbyaddr always
I am trying to lookup a value e.g. 123abc456 from a table but the
I am trying to achieve a gradient + text shadow effect in Chrome/Safari using
Trying to achieve something like this using recursion: if (m > n) return; Foo
im trying to achieve something that i thought it was easy, but the reality
Im trying to achieve a design that has five columns with fluid width, but
This is a simplified example of what I am trying to achieve, I'm relatively

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.