Spring-shell使用

时间:2017-03-29 10:02:37

标签: spring-shell

我试图使用spring-shell。  创建了这样的类:

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

并有这样的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>

启动应用程序的类:

public class Main {

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

但结果我只是进入了控制台而且是“构造函数”。虽然我通过了论证,但他仍然传递了反对意见。

如何使其有效?

1 个答案:

答案 0 :(得分:0)

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