简体   繁体   English

创建Java电子邮件批处理程序时,我应该使用Spring Framework jar文件还是Spring Batch jar文件?

[英]Should I use the Spring Framework jar files or Spring Batch jar files while creating a java email batch program?

I am trying to create a java email batch program that sends an email with an attachment each day to a specific email address, and I have to use Spring as the framework for this program. 我正在尝试创建一个Java电子邮件批处理程序,该程序每天将带有附件的电子邮件发送到特定的电子邮件地址,并且我必须使用Spring作为该程序的框架。 It is not going to be a web application, but since I'm implementing Spring into this, how would I go about this? 它不会是一个Web应用程序,但是既然我要在其中实现Spring,那么我将如何处理呢? I am totally new to Spring (and Java for that matter), but am unsure of which direction I need to go. 我对Spring(以及Java)完全陌生,但是不确定我应该朝哪个方向发展。 Which jar files do I need? 我需要哪些jar文件? Spring Batch or Spring Framework? Spring Batch或Spring Framework? Also, where can I download the jar files for Spring Framework? 另外,在哪里可以下载Spring Framework的jar文件? The spring.io site won't let me download those jar files. spring.io网站不允许我下载这些jar文件。

I very strongly suggest you use a build tool that handles dependency management. 我强烈建议您使用处理依赖关系管理的构建工具。 Such tools are Ant+Ivy, Maven and Gradle. 这样的工具是Ant + Ivy,Maven和Gradle。 They will take care of downloading the appropriate jars based on your declaration of what dependencies you need and will take care of all the transitive dependencies. 他们将根据您对所需依赖项的声明来下载适当的jar,并会处理所有传递性依赖项。

One good way of getting started with Spring Batch is to follow this tutorial using either Maven or Gradle (the latter would probably be easier since you don't need to install it - the tutorial's code has a wrapper). 开始使用Spring Batch的一个好方法是使用Maven或Gradle来学习教程(后者可能会更容易,因为您不需要安装它-本教程的代码具有包装器)。

The tutorial uses Spring Boot which vastly simplifies Spring configuration (which is a serious benefit especially for someone who is new to Spring) 本教程使用Spring Boot极大地简化了Spring配置(这对于特别是Spring新手来说是一个很大的好处)

As others already told you, I personally would not start any spring based project (means: any project) without maven! 正如其他人已经告诉您的那样,如果没有行家,我个人不会启动任何基于Spring的项目(意味着:任何项目)! You have so much benefits from it, not only depencency management. 您可以从中获得很多好处,而不仅仅是依赖管理。

To start a spring app outside an application context: 要在应用程序上下文之外启动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();
}

I'd recommend starting with Spring Boot which will handle all of that for you. 我建议从Spring Boot开始,它将为您处理所有这一切。 As others have mentioned, pick a build tool (Maven or Gradle) and follow the guide we provide on building a batch application here: http://spring.io/guides/gs/batch-processing/ . 正如其他人提到的那样,选择一个构建工具(Maven或Gradle),并按照我们在此处提供的有关构建批处理应用程序的指南进行操作: http : //spring.io/guides/gs/batch-processing/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM