Search code examples
spring-shell

Spring-shell usage


I'm trying to use spring-shell. Created such class:

@Component
public class T implements CommandMarker {

public T() {
    System.out.println("T Constructor");
}

@CliCommand(value = "trans", help = "translate")
public String translate(@CliOption(key = { "msg" }, 
    mandatory = false, help = "The hello world message")
    final String msg) {
    System.out.println("!!! " + msg);
    return "!!! " + msg;
  }
}

and have such spring-shell-plugin.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.1.xsd">   

   <context:component-scan base-package="com" /> 

</beans>

Class that starting application:

public class Main {

public static void main(String[] args) {
    ClassPathXmlApplicationContext context =
            new ClassPathXmlApplicationContext("classpath*:/META-INF/spring/spring-shell-plugin.xml");
    context.start();
}
}

But as a result I'm just getting in console only 'T Constructor' althought I'm passing arguments 'trans --msg f'.

How to make it works?


Solution

  • public static void main(String[] args) throws IOException {
        Bootstrap.main(args);
    }