Когда я тестирую свою весеннюю партию (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>
application.properties:
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)
Когда вы используете @SpringBootApplication
, функция @SpringBootApplication
Spring включена по умолчанию. Поскольку у вас есть весенние пакетные зависимости, загруженные в ваш путь к классам, также включена функция Spring Batch AutoConfiguration.
Во время запуска приложения автоконфигурация Spring Batch (BatchAutoConfiguration) создает Runner и запускает все задания, определенные в вашем BatchConfig.
Вы можете отключить это поведение, установив свойство spring.batch.job.enabled
в false
в свойствах вашего приложения или просто исключив Autoconfiguration for Batch так же, как и вы.
Адаптировано из qaru.site/questions/15628079/...