question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Waiting for DataSourceInitializer to run schema.sql

See original GitHub issue

I’m using Spring Boot 2.1.2 and Shedlock 2.2.1.

I’m using schema.sql (as documented at https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto-initialize-a-database-using-spring-jdbc ) to create the schema used by shedlock. When using @EnableSchedulerLock Spring Boot isn’t running src/main/resources/schema.sql as it should resulting in Spring Boot failing to start up.

Here’s SchedulingConfig.java:

import javax.sql.DataSource;

import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

/** Scheduling configuration and scheduled tasks.
 * @author Craig Andrews
 *
 */
@EnableScheduling
@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "PT10M")
public class SchedulingConfig {
	@Value("${schedlock.schema}")
	private String schedLockSchema;

	@Bean
	public LockProvider lockProvider(final DataSource dataSource) {
		return new JdbcTemplateLockProvider(dataSource, schedLockSchema + ".shedlock");
	}

}

Here’s src/main/resources/schema.sql:

BEGIN;
CREATE SCHEMA IF NOT EXISTS myapp;
COMMIT;

And here’s the startup output (Liquibase is the first error as the schema it uses is created by schema.sql, and that isn’t happening):

2019-01-30 17:04:26.463  INFO 3045 --- [           main] c.i.t.IndexControllerTest                : No active profile set, falling back to default profiles: default
2019-01-30 17:04:26.766  INFO 3045 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-30 17:04:26.783  INFO 3045 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 17ms. Found 2 repository interfaces.
2019-01-30 17:04:26.886  INFO 3045 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'schedulingConfig' of type [com.integralblue.myapp.SchedulingConfig$$EnhancerBySpringCGLIB$$a45017c8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-30 17:04:26.889  INFO 3045 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-30 17:04:26.899  INFO 3045 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-30 17:04:26.913  INFO 3045 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [com.zaxxer.hikari.HikariDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-30 17:04:26.916  INFO 3045 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'lockProvider' of type [net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-30 17:04:26.988  INFO 3045 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$dc5eaadf] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-30 17:04:27.052  INFO 3045 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-4 - Starting...
2019-01-30 17:04:27.053  INFO 3045 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-4 - Start completed.
2019-01-30 17:04:27.200  INFO 3045 --- [           main] liquibase.executor.jvm.JdbcExecutor      : SELECT COUNT(*) FROM MYAPP.DATABASECHANGELOGLOCK
2019-01-30 17:04:27.201  INFO 3045 --- [           main] liquibase.executor.jvm.JdbcExecutor      : CREATE TABLE MYAPP.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))
2019-01-30 17:04:27.202  WARN 3045 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LockException: liquibase.exception.DatabaseException: Schema "MYAPP" not found; SQL statement:
CREATE TABLE MYAPP.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID)) [90079-197] [Failed SQL: CREATE TABLE MYAPP.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]
2019-01-30 17:04:27.202  INFO 3045 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-4 - Shutdown initiated...
2019-01-30 17:04:27.205  INFO 3045 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-4 - Shutdown completed.
2019-01-30 17:04:27.213  INFO 3045 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-30 17:04:27.214 ERROR 3045 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LockException: liquibase.exception.DatabaseException: Schema "MYAPP" not found; SQL statement:
CREATE TABLE MYAPP.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID)) [90079-197] [Failed SQL: CREATE TABLE MYAPP.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]
``

By removing the `@EnableSchedulerLock`, everything starts up and runs fine without error.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lukas-krecancommented, Feb 4, 2019

fixed in 2.3.0

0reactions
candrewscommented, Feb 4, 2019

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Spring Boot 2.0 application does not run schema.sql?
Check the documents here. In a JPA-based app, you can choose to let Hibernate create the schema or use schema.sql, but you cannot...
Read more >
14. Integration Testing - Spring
Defines metadata that is used to determine how to parse and execute SQL scripts ... fail the test but rather waits for the...
Read more >
Working With Relational Database Using R2dbc DatabaseClient
Here we use a schema.sql to create the tables and the data.sql to initialize some sample data. -- schema.sql. CREATE TABLE IF NOT ......
Read more >
SQL Developer – A great tool and better ways to use it
Compared to other tools for Oracle database, this comes in handy for database development and support tasks. Schema Browser – Scan the database....
Read more >
A Walkthrough of SQL Schema - SQLShack
We define SQL Schema as a logical collection of database objects. ... Alternatively, we can run the script by specifying a schema name....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found