lundi 20 avril 2015

Spring's method injection

I'm reading the Spring current version's documentation and have problems with understanding of the chapter 5.4.6 Method Injection. As far as I got that we can provide the ability of recreation a bean every time we call the method using the bean. Documentation provides the following code example:

public class CommandManager implements ApplicationContextAware {

    //Imports and comments were omitted
    private ApplicationContext applicationContext;

    public Object process(Map commandState) {
        Command command = createCommand();
        command.setState(commandState);
        return command.execute();
    }

    protected Command createCommand() {
        return this.applicationContext.getBean("command", Command.class);
    }

    public void setApplicationContext(
            ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

where ApplicationContextAware interface looks like:

public interface ApplicationContextAware {

    //JavaDocs ommited
    void setApplicationContext(ApplicationContext applicationContext) throws BeansException;

}

So, what is the method public Object process(Map commandState)? Is it a callback? If so, where is it going to be called and who performs that call? After all, it's not clear why the bean is goign to be recreated every time it needed.

Aucun commentaire:

Enregistrer un commentaire