English 中文(简体)
2. Spring 注射方法
原标题:Spring Lookup method injection not working

我正试图利用一个简单的例子来寻找注射方法。 但是,在通过这种方法注射针头方面似乎失败了。

我有一个简单的信条:

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 +     +
                 } ;
    }
}

我试图将<密码>DemoBean注入另一个信条,即: 不动产:

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>

试图创建<代码>的事例 PropertyBean。 我能够这样做。 但当我做以下工作时。 我对DemoBean财产感到无足轻重的例外情况(因为海滩不会被注入!)

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.

最佳回答

bean property shouldn t bejectioned. 如我所知,春季执行<代码>createBean。 您的计算方法,如您打电话pb.createBean(,应交回DemoBean。 但是,你没有将任何东西分配到<条码>bean中的财产,<条码>ProperyBean,因此,它没有任何东西可以取消。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签