springbatch自學之路-02(如何搭建一個springbatch項目)

目錄

1.通過連接外網的方式

2.通過idea自帶的springboot初始化的方式

3.通過自己新建maven工程的方式


1.通過連接外網的方式

(1)訪問https://start.spring.io/

(2)配置好maven座標以後,添加maven依賴,搜索batch和h2添加即可

(3)點擊generate按鈕

(4)然後直接點擊下載即可。

(5)用idea打開項目後可以看到所有的依賴已經配置好了。

(6)pom文件如下所示

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.3.0.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.springbatch</groupId>
	<artifactId>demo_01</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo_01</name>
	<description>Demo project for Spring batch</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-batch</artifactId>
		</dependency>

		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.batch</groupId>
			<artifactId>spring-batch-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

(7)運行一下項目

看到項目正常啓動,日誌如下,說明springbatch框架我們已經搭建好了。

D:\software\java\jdk_1.8\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\software\idea\IntelliJ IDEA 2018.3.1\lib\idea_rt.jar=50313:D:\software\idea\IntelliJ IDEA 2018.3.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\software\idea\IntelliJ IDEA 2018.3.1\lib\idea_rt.jar;D:\software\idea\IntelliJ IDEA 2018.3.1\plugins\junit\lib\junit-rt.jar;D:\software\idea\IntelliJ IDEA 2018.3.1\plugins\junit\lib\junit5-rt.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\platform\junit-platform-launcher\1.6.2\junit-platform-launcher-1.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\platform\junit-platform-engine\1.6.2\junit-platform-engine-1.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\platform\junit-platform-commons\1.6.2\junit-platform-commons-1.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\vintage\junit-vintage-engine\5.6.2\junit-vintage-engine-5.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\junit\junit\4.13\junit-4.13.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\software\java\jdk_1.8\jre\lib\charsets.jar;D:\software\java\jdk_1.8\jre\lib\deploy.jar;D:\software\java\jdk_1.8\jre\lib\ext\access-bridge-64.jar;D:\software\java\jdk_1.8\jre\lib\ext\cldrdata.jar;D:\software\java\jdk_1.8\jre\lib\ext\dnsns.jar;D:\software\java\jdk_1.8\jre\lib\ext\jaccess.jar;D:\software\java\jdk_1.8\jre\lib\ext\jfxrt.jar;D:\software\java\jdk_1.8\jre\lib\ext\localedata.jar;D:\software\java\jdk_1.8\jre\lib\ext\nashorn.jar;D:\software\java\jdk_1.8\jre\lib\ext\sunec.jar;D:\software\java\jdk_1.8\jre\lib\ext\sunjce_provider.jar;D:\software\java\jdk_1.8\jre\lib\ext\sunmscapi.jar;D:\software\java\jdk_1.8\jre\lib\ext\sunpkcs11.jar;D:\software\java\jdk_1.8\jre\lib\ext\zipfs.jar;D:\software\java\jdk_1.8\jre\lib\javaws.jar;D:\software\java\jdk_1.8\jre\lib\jce.jar;D:\software\java\jdk_1.8\jre\lib\jfr.jar;D:\software\java\jdk_1.8\jre\lib\jfxswt.jar;D:\software\java\jdk_1.8\jre\lib\jsse.jar;D:\software\java\jdk_1.8\jre\lib\management-agent.jar;D:\software\java\jdk_1.8\jre\lib\plugin.jar;D:\software\java\jdk_1.8\jre\lib\resources.jar;D:\software\java\jdk_1.8\jre\lib\rt.jar;D:\document\spring_batch\demo_01\demo_01\target\test-classes;D:\document\spring_batch\demo_01\demo_01\target\classes;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-starter-batch\2.3.0.RELEASE\spring-boot-starter-batch-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-starter\2.3.0.RELEASE\spring-boot-starter-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot\2.3.0.RELEASE\spring-boot-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-autoconfigure\2.3.0.RELEASE\spring-boot-autoconfigure-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-starter-logging\2.3.0.RELEASE\spring-boot-starter-logging-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.2\log4j-to-slf4j-2.13.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\apache\logging\log4j\log4j-api\2.13.2\log4j-api-2.13.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\document\eclipse_workspace\local_repository\local_repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-starter-jdbc\2.3.0.RELEASE\spring-boot-starter-jdbc-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\batch\spring-batch-core\4.2.2.RELEASE\spring-batch-core-4.2.2.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\fasterxml\jackson\core\jackson-databind\2.11.0\jackson-databind-2.11.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\fasterxml\jackson\core\jackson-annotations\2.11.0\jackson-annotations-2.11.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\fasterxml\jackson\core\jackson-core\2.11.0\jackson-core-2.11.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\io\micrometer\micrometer-core\1.5.1\micrometer-core-1.5.1.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\hdrhistogram\HdrHistogram\2.1.12\HdrHistogram-2.1.12.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\javax\batch\javax.batch-api\1.0\javax.batch-api-1.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\codehaus\jettison\jettison\1.2\jettison-1.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\batch\spring-batch-infrastructure\4.2.2.RELEASE\spring-batch-infrastructure-4.2.2.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\retry\spring-retry\1.2.5.RELEASE\spring-retry-1.2.5.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-aop\5.2.6.RELEASE\spring-aop-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-beans\5.2.6.RELEASE\spring-beans-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-context\5.2.6.RELEASE\spring-context-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-expression\5.2.6.RELEASE\spring-expression-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-tx\5.2.6.RELEASE\spring-tx-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\h2database\h2\1.4.200\h2-1.4.200.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-starter-test\2.3.0.RELEASE\spring-boot-starter-test-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-test\2.3.0.RELEASE\spring-boot-test-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\boot\spring-boot-test-autoconfigure\2.3.0.RELEASE\spring-boot-test-autoconfigure-2.3.0.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\document\eclipse_workspace\local_repository\local_repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\assertj\assertj-core\3.16.1\assertj-core-3.16.1.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\jupiter\junit-jupiter\5.6.2\junit-jupiter-5.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\jupiter\junit-jupiter-api\5.6.2\junit-jupiter-api-5.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\jupiter\junit-jupiter-params\5.6.2\junit-jupiter-params-5.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\junit\jupiter\junit-jupiter-engine\5.6.2\junit-jupiter-engine-5.6.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\mockito\mockito-core\3.3.3\mockito-core-3.3.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\net\bytebuddy\byte-buddy\1.10.10\byte-buddy-1.10.10.jar;D:\document\eclipse_workspace\local_repository\local_repository\net\bytebuddy\byte-buddy-agent\1.10.10\byte-buddy-agent-1.10.10.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\mockito\mockito-junit-jupiter\3.3.3\mockito-junit-jupiter-3.3.3.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-core\5.2.6.RELEASE\spring-core-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-jcl\5.2.6.RELEASE\spring-jcl-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-test\5.2.6.RELEASE\spring-test-5.2.6.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\xmlunit\xmlunit-core\2.7.0\xmlunit-core-2.7.0.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\batch\spring-batch-test\4.2.2.RELEASE\spring-batch-test-4.2.2.RELEASE.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\hamcrest\hamcrest-core\2.2\hamcrest-core-2.2.jar;D:\document\eclipse_workspace\local_repository\local_repository\org\springframework\spring-jdbc\5.2.6.RELEASE\spring-jdbc-5.2.6.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.springbatch.demo_01.Demo01ApplicationTests,contextLoads
20:12:39.492 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
20:12:39.509 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
20:12:39.538 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.springbatch.demo_01.Demo01ApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
20:12:39.553 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.springbatch.demo_01.Demo01ApplicationTests], using SpringBootContextLoader
20:12:39.556 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.springbatch.demo_01.Demo01ApplicationTests]: class path resource [com/springbatch/demo_01/Demo01ApplicationTests-context.xml] does not exist
20:12:39.556 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.springbatch.demo_01.Demo01ApplicationTests]: class path resource [com/springbatch/demo_01/Demo01ApplicationTestsContext.groovy] does not exist
20:12:39.556 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.springbatch.demo_01.Demo01ApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
20:12:39.556 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.springbatch.demo_01.Demo01ApplicationTests]: Demo01ApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
20:12:39.591 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.springbatch.demo_01.Demo01ApplicationTests]
20:12:39.658 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\document\spring_batch\demo_01\demo_01\target\classes\com\springbatch\demo_01\Demo01Application.class]
20:12:39.660 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.springbatch.demo_01.Demo01Application for test class com.springbatch.demo_01.Demo01ApplicationTests
20:12:39.793 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.springbatch.demo_01.Demo01ApplicationTests]: using defaults.
20:12:39.793 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
20:12:39.803 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [javax/servlet/ServletContext]
20:12:39.813 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@65c7a252, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4d154ccd, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@229c6181, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4686afc2, org.springframework.test.context.transaction.TransactionalTestExecutionListener@1e0b4072, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@791f145a, org.springframework.test.context.event.EventPublishingTestExecutionListener@38cee291, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@4b45a2f5, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@f09733f, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@e350b40, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@41a0aa7d, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@2794eab6, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@6340e5f0]
20:12:39.818 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@4145bad8 testClass = Demo01ApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@d86a6f testClass = Demo01ApplicationTests, locations = '{}', classes = '{class com.springbatch.demo_01.Demo01Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5e82df6a, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@50a638b5, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@130161f7, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@479d31f3, org.springframework.boot.test.context.SpringBootTestArgs@1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].
20:12:39.831 [main] DEBUG org.springframework.test.context.support.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[DefaultTestContext@4145bad8 testClass = Demo01ApplicationTests, testInstance = com.springbatch.demo_01.Demo01ApplicationTests@2034b64c, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@d86a6f testClass = Demo01ApplicationTests, locations = '{}', classes = '{class com.springbatch.demo_01.Demo01Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5e82df6a, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@50a638b5, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@130161f7, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@479d31f3, org.springframework.boot.test.context.SpringBootTestArgs@1], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]]].
20:12:39.859 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.0.RELEASE)

2020-05-22 20:12:40.085  INFO 3156 --- [           main] c.s.demo_01.Demo01ApplicationTests       : Starting Demo01ApplicationTests on LAPTOP-SRJM9GEI with PID 3156 (started by 張琴 in D:\document\spring_batch\demo_01\demo_01)
2020-05-22 20:12:40.087  INFO 3156 --- [           main] c.s.demo_01.Demo01ApplicationTests       : No active profile set, falling back to default profiles: default
2020-05-22 20:12:41.171  INFO 3156 --- [           main] c.s.demo_01.Demo01ApplicationTests       : Started Demo01ApplicationTests in 1.308 seconds (JVM running for 2.594)

Process finished with exit code 0

2.通過idea自帶的springboot初始化的方式

1.新建項目

2.點擊next,配置maven座標

3.添加batch和H2的依賴,點擊next

4.直接點擊finish

5.可以看到項目跟剛剛新建的demo1長得一樣的

6.運行項目,項目正常啓動

3.通過自己新建maven工程的方式

1.新建maven項目

2.直接點擊next

3.填寫完maven座標後,點擊next

4.直接點擊finish

5.看到一個空的項目,此時需要添加依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.springbatch</groupId>
    <artifactId>demo_03</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

6.可以看到依賴已經添加完成

7.新建啓動類 SpringBatchConfig.java

package com.springbatch;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * SpringBatchDemo項目啓動類
 *
 * @Package: PACKAGE_NAME
 * @ClassName: com.springbatch.SpringBatchConfig
 * @author: zq
 * @since: 2020/5/22 20:31
 * @version: 1.0
 * @Copyright: 2020 zq. All rights reserved.
 */
@SpringBootApplication
public class SpringBatchConfig {

    public static void main(String[] args) {

        SpringApplication.run(SpringBatchConfig.class, args);

    }

}

8.啓動項目

項目正常啓動。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章