我正在尝试创建一个java电子邮件批处理程序,该程序每天将带有附件的电子邮件发送到特定的电子邮件地址,我必须使用Spring作为该程序的框架。它不会是一个web应用程序,但是既然我在其中实现了Spring,我该怎么做呢?我完全不熟悉Spring (就这一点而言,Java也是如此),但我不确定我需要朝哪个方向发展。我需要哪些jar文件?Spring Batch还是Spring Framework?另外,我可以在哪里下载Spring Framework的jar文件?spring.io站点不允许我下载这些jar文件。
发布于 2014-04-17 00:18:21
我强烈建议您使用处理依赖项管理的构建工具。这样的工具有Ant+Ivy、Maven和Gradle。它们将根据您对所需依赖项的声明下载适当的jars,并处理所有可传递依赖项。
开始使用Spring Batch的一个好方法是使用Maven或Gradle遵循this教程(后者可能更容易,因为您不需要安装它-教程的代码有一个包装器)。
发布于 2014-04-17 21:10:14
正如其他人已经告诉你的,我个人不会在没有maven的情况下启动任何基于spring的项目(意思是:任何项目)!你从中得到了很多好处,不仅仅是依赖管理。
要在应用程序上下文之外启动spring应用程序:
@Configuration
public class AppConfig {
//any bean configurations here
}
//your entry class
static void main(String args[]) {
//get a reference to the spring context. use this context throughout your app!
ApplicationContext ctx = new AnnotationConfigApplicationContext(CacheConfig.class).get();
//optain any beans from the context. inside these beans, you can use any spring feature you like, eg @Autowired
ctx.getBean(YourBean.class).executeMethod();
}发布于 2014-04-17 22:38:48
我建议从Spring Boot开始,它将为您处理所有这些问题。正如其他人所提到的,选择一个构建工具(Maven或Gradle),并遵循我们在这里提供的构建批处理应用程序的指南:http://spring.io/guides/gs/batch-processing/。
https://stackoverflow.com/questions/23113674
复制相似问题