我想創建Spring控制檯應用程序(從命令行運行maven,例如:mvn exec:java -Dexec.mainClass =「package.MainClass」)。使用註釋配置的Spring控制檯應用程序
這個應用程序我想要某種服務和dao層。我知道如何做一個Web應用程序,但我還沒有找到任何有關如何在控制檯應用程序的情況下(leter可能與Swing)的信息。
我想創造的東西,如:
public interface SampleService {
public String getHelloWorld();
}
@Service
public class SampleServiceImpl implements SampleService {
public String getHelloWorld() {
return "HelloWorld from Service!";
}
}
public class Main {
@Autowired
SampleService sampleService;
public static void main(String [] args) {
Main main = new Main();
main.sampleService.getHelloWorld();
}
}
這可能嗎? 我可以在某處找到一個如何去做的例子嗎?
此外,如果像我一樣,你碰巧註釋你的配置: ctx = new AnnotationConfigApplicationContext(MyConfig.class); – 2012-03-30 01:19:27
如何將命令行參數提供給應用程序上下文,以便上下文又可以將這些參數注入到bean中? – 2015-09-18 16:04:38