0

I have a small server which was in need of a simple console to enter a commands. After a bit of searching i found spring shell, which does the job.

Some of my commands need access to the server instance object.

How can i (autowire?) my server object instance into my spring shell command so that i can access my server object instance in a spring shell command?

Bootstrap constructor seem to creating the application context and immediately finds the user shell commands.

I tried to use:

bootstrap.getApplicationContext().getBeanFactory().registerSingleton(class, myserverinstance)

But this can only be done after Bootstrap constructor is called and then it is too late.

Tinus Tate
  • 2,237
  • 2
  • 12
  • 33

1 Answers1

1

I'm not sure I understand.

First of all, is the Spring Shell process the same process as what is running your "server"?

Regarding wiring, Spring Shell is no different than any other Spring application. I understand that you already have an instance of your "server" bean. The best thing to do in that case is to use a FactoryBean

Hope that helps

ebottard
  • 1,997
  • 2
  • 12
  • 14
  • I've just implemented your suggestion and it works! I had to create a plain java singleton which holds my server instance so that the factorybean could get the server instance in the getObject() method. – Tinus Tate Feb 01 '16 at 08:15