iT邦幫忙

0

改寫 spring boot batch

  • 分享至 

  • xImage

我下載了 spring boot batch 的範例,想改寫成打資料寫入mssql。

範例的連結
https://spring.io/guides/gs/batch-processing/

範例的git
git clone https://github.com/spring-guides/gs-batch-processing.git

加了application.properties

spring.mvc.view.prefix=/WEB-INF/view
spring.mvc.view.suffix=.html
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=hypons
spring.datasource.username=Myusername
spring.datasource.password=Mypassword
spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.batch.job.enabled=false

改寫了 sql 語法

USE hypons
CREATE TABLE people  (
    person_id BIGINT IDENTITY NOT NULL PRIMARY KEY,
    first_name VARCHAR(20),
    last_name VARCHAR(20)
);

最後 console 給我這個

19:27:36.115 [Thread-1] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@5044742e

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

2022-04-18 19:27:36.418  INFO 16897 --- [  restartedMain] c.e.b.BatchProcessingApplication         : Starting BatchProcessingApplication using Java 1.8.0_301 on Hyponss-MacBook-Air.local with PID 16897 (/Users/hypons/Desktop/complete/target/classes started by hypons in /Users/hypons/Desktop/complete)
2022-04-18 19:27:36.418  INFO 16897 --- [  restartedMain] c.e.b.BatchProcessingApplication         : No active profile set, falling back to default profiles: default
2022-04-18 19:27:36.459  INFO 16897 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-04-18 19:27:36.459  INFO 16897 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-04-18 19:27:37.106  INFO 16897 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-04-18 19:27:37.126  INFO 16897 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14 ms. Found 0 JPA repository interfaces.
2022-04-18 19:27:37.729  INFO 16897 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2022-04-18 19:27:37.736  INFO 16897 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-04-18 19:27:37.736  INFO 16897 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-04-18 19:27:37.937  INFO 16897 --- [  restartedMain] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2022-04-18 19:27:37.943  INFO 16897 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-04-18 19:27:37.943  INFO 16897 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1484 ms
2022-04-18 19:27:38.100  INFO 16897 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-04-18 19:27:38.499  INFO 16897 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-04-18 19:27:38.653  INFO 16897 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-04-18 19:27:38.684  INFO 16897 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.4.Final
2022-04-18 19:27:38.803  INFO 16897 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-04-18 19:27:38.873  INFO 16897 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
2022-04-18 19:27:38.991  INFO 16897 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-04-18 19:27:38.997  INFO 16897 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-04-18 19:27:39.142  WARN 16897 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-04-18 19:27:39.429  WARN 16897 --- [  restartedMain] o.s.b.a.batch.JpaBatchConfigurer         : JPA does not support custom isolation levels, so locks may not be taken when launching Jobs
2022-04-18 19:27:39.439  INFO 16897 --- [  restartedMain] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: SQLSERVER
2022-04-18 19:27:39.455  INFO 16897 --- [  restartedMain] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2022-04-18 19:27:39.532  INFO 16897 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2022-04-18 19:27:39.574  INFO 16897 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path ''
2022-04-18 19:27:39.590  INFO 16897 --- [  restartedMain] c.e.b.BatchProcessingApplication         : Started BatchProcessingApplication in 3.465 seconds (JVM running for 4.335)
2022-04-18 19:27:39.605  INFO 16897 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-04-18 19:27:39.607  INFO 16897 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-04-18 19:27:39.608  INFO 16897 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

之後查看資料庫也沒動靜,但console也沒報錯,請問現在情況是怎樣呢?

註:
如果不改寫範例,直接執行會是這樣的console

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.2.RELEASE) 2020-08-10 21:19:13.517 INFO 50375 --- [ main] c.e.b.BatchProcessingApplication : Starting BatchProcessingApplication v0.0.1-SNAPSHOT on mba-2 with PID 50375 (/Users/#{myname}/projects/gs-batch-processing/complete/target/batch-processing-0.0.1-SNAPSHOT.jar started by #{myname} in /Users/#{myname}/projects/gs-batch-processing/complete/target) 2020-08-10 21:19:13.520 INFO 50375 --- [ main] c.e.b.BatchProcessingApplication : No active profile set, falling back to default profiles: default 2020-08-10 21:19:14.662 INFO 50375 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2020-08-10 21:19:14.671 WARN 50375 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=org.hsqldb.jdbcDriver was not found, trying direct instantiation. 2020-08-10 21:19:15.098 INFO 50375 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (feature not supported) 2020-08-10 21:19:15.103 INFO 50375 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2020-08-10 21:19:15.430 INFO 50375 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL 2020-08-10 21:19:15.716 INFO 50375 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor. 2020-08-10 21:19:15.825 INFO 50375 --- [ main] c.e.b.BatchProcessingApplication : Started BatchProcessingApplication in 2.835 seconds (JVM running for 3.415) 2020-08-10 21:19:15.826 INFO 50375 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: [] 2020-08-10 21:19:15.912 INFO 50375 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{run.id=1}] 2020-08-10 21:19:15.992 INFO 50375 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1] 2020-08-10 21:19:16.062 INFO 50375 --- [ main] c.e.batchprocessing.PersonItemProcessor : Converting (firstName: Jill, lastName: Doe) into (firstName: JILL, lastName: DOE) 2020-08-10 21:19:16.062 INFO 50375 --- [ main] c.e.batchprocessing.PersonItemProcessor : Converting (firstName: Joe, lastName: Doe) into (firstName: JOE, lastName: DOE) 2020-08-10 21:19:16.062 INFO 50375 --- [ main] c.e.batchprocessing.PersonItemProcessor : Converting (firstName: Justin, lastName: Doe) into (firstName: JUSTIN, lastName: DOE) 2020-08-10 21:19:16.063 INFO 50375 --- [ main] c.e.batchprocessing.PersonItemProcessor : Converting (firstName: Jane, lastName: Doe) into (firstName: JANE, lastName: DOE) 2020-08-10 21:19:16.063 INFO 50375 --- [ main] c.e.batchprocessing.PersonItemProcessor : Converting (firstName: John, lastName: Doe) into (firstName: JOHN, lastName: DOE) 2020-08-10 21:19:16.074 INFO 50375 --- [ main] o.s.batch.core.step.AbstractStep : Step: [step1] executed in 82ms 2020-08-10 21:19:16.080 INFO 50375 --- [ main] c.e.b.JobCompletionNotificationListener : !!! JOB FINISHED! Time to verify the results 2020-08-10 21:19:16.083 INFO 50375 --- [ main] c.e.b.JobCompletionNotificationListener : Found <firstName: JILL, lastName: DOE> in the database. 2020-08-10 21:19:16.083 INFO 50375 --- [ main] c.e.b.JobCompletionNotificationListener : Found <firstName: JOE, lastName: DOE> in the database. 2020-08-10 21:19:16.083 INFO 50375 --- [ main] c.e.b.JobCompletionNotificationListener : Found <firstName: JUSTIN, lastName: DOE> in the database. 2020-08-10 21:19:16.083 INFO 50375 --- [ main] c.e.b.JobCompletionNotificationListener : Found <firstName: JANE, lastName: DOE> in the database. 2020-08-10 21:19:16.083 INFO 50375 --- [ main] c.e.b.JobCompletionNotificationListener : Found <firstName: JOHN, lastName: DOE> in the database. 2020-08-10 21:19:16.088 INFO 50375 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED] in 107ms 2020-08-10 21:19:16.092 INFO 50375 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-08-10 21:19:16.102 INFO 50375 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
pico2k iT邦新手 5 級 ‧ 2022-04-19 10:27:15 檢舉
請檢查一下SQL Server的設定,例如帳密是否正確,帳號的權限是否設定正確...
hypons iT邦新手 5 級 ‧ 2022-04-20 00:40:47 檢舉
密碼是正確的,因為同樣的設定也用在其他專案。但權限我沒有設定,這個會有影響嗎?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答