spring批处理mysql问题

vybvopom  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(573)

当我测试springbatch(v4.0.1)应用程序时。对于内存数据库中的h2,它的工作方式很有魅力,但是当我使用mysql时,它无法运行commandlinerunner,对此有什么解释吗?
我的pom文件:

<dependencies>

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
         <groupId>org.jsoup</groupId>
         <artifactId>jsoup</artifactId>
         <version>1.11.3</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>   
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

应用程序属性:

spring.jpa.hibernate.ddl-auto=update
 spring.jpa.show-sql=true
 spring.jpa.open-in-view=false
 spring.datasource.url=jdbc:Mysql://localhost/myDB?useSSL=false
 spring.datasource.username=root
 spring.datasource.password=87654321
 spring.datasource.driver-class-name=com.mysql.jdbc.Driver

慰问:

main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
    main] o.s.b.a.batch.JpaBatchConfigurer         : JPA does not support custom isolation levels, so locks may not be taken when launching Jobs
    main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: MYSQL
    main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
    main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
    main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
    main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
    main] io.nader.org.ScrapOneApplication         : Started ScrapOneApplication in 65.255 seconds (JVM running for 76.788)
    main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: [--spring.output.ansi.enabled=always]
    main] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
    main] o.s.jdbc.support.SQLErrorCodesFactory    : SQLErrorCodes loaded: [DB2, Derby, H2, HDB, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
    main] ConditionEvaluationReportLoggingListener : 

   Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.        
  2018-07-07 18:08:42.968 ERROR 780 --- [           main] o.s.boot.SpringApplication               : Application run failed

   java.lang.IllegalStateException: Failed to execute CommandLineRunner                                                     
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800)
1tuwyuhd

1tuwyuhd1#

当你使用 @SpringBootApplication ,默认情况下启用spring的自动配置。因为类路径中加载了spring批处理依赖项,所以spring批处理自动配置也被启用。
在应用程序启动期间,springbatch的autoconfiguration(batchautoconfiguration)创建一个运行程序,并运行batchconfig中定义的所有作业。
您可以通过以下任一设置禁用此行为 spring.batch.job.enabled 属性到 false 在应用程序属性中,或者简单地排除批处理的自动配置,就像您所做的那样。
请参阅这里和这里的更多信息。
改编自https://stackoverflow.com/a/50191789/6572971

相关问题