Can't able to connect redshift from my springboot application using JPA - spring-boot

i am working on Springboot application and need to store data into redshift using the spring-boot-starter-data-jpa.
But i can't able to acheive the connection between the redshift and my springboot application.
Here is my dependency from pom.xml:
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42</artifactId>
<version>1.2.43.1067</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.7.RELEASE</version>
</dependency>
My Application.properties
spring.datasource.url=jdbc:redshift://hostaddress
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.amazon.redshift.jdbc.Driver
spring.jpa.hibernate.ddl-auto = create
My Java Model class:
#Entity
#Table(schema = "public", name = "SampleModel")
public class SampleModel {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int year;
private int month;
private BigDecimal price;
private BigDecimal total;
}
Exception StackTrace:
2021-01-04 19:00:53.378 INFO 5152 --- [ main] org.neo4j.ogm.metadata.DomainInfo : Building interface class map for 32 classes
2021-01-04 19:00:53.390 INFO 5152 --- [ main] org.neo4j.ogm.metadata.DomainInfo : Post-processing complete
2021-01-04 19:00:55.768 INFO 5152 --- [ task-1] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. ([Amazon][JDBC](10220) Driver does not support this optional feature.)
2021-01-04 19:00:55.797 INFO 5152 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-01-04 19:00:57.056 INFO 5152 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL81Dialect
2021-01-04 19:00:57.450 ERROR 5152 --- [ task-1] o.h.e.j.e.internal.JdbcEnvironmentImpl : Could not fetch the SequenceInformation from the database
java.sql.SQLException: [Amazon](500310) Invalid operation: relation "information_schema.sequences" does not exist;
at com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.client.PGMessagingContext.handleErrorResponse(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.client.PGMessagingContext.handleMessage(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.jdbc.communications.InboundMessagesPipeline.getNextMessageOfClass(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.client.PGMessagingContext.doMoveToNextClass(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.client.PGMessagingContext.moveThroughMetadata(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.client.PGMessagingContext.getNoData(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.client.PGClient.directExecuteExtraMetadataWithMessage(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.dataengine.PGQueryExecutor$CallableExecuteTask.call(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at com.amazon.redshift.dataengine.PGQueryExecutor$CallableExecuteTask.call(Unknown Source) ~[redshift-jdbc42-1.2.43.1067.jar:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
Caused by: com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: relation "information_schema.sequences" does not exist;
... 13 common frames omitted
2021-01-04 19:00:57.588 INFO 5152 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-01-04 19:00:57.594 INFO 5152 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
Did anyone faced this issue or know how to resolve this issue?

There's nothing wrong with your connection - you connected successfully. But your application is trying to read from information_schema.sequences table, which does not exist in Redshift.
It looks like you have JPA objects with identifiers bound to sequences and you're using PostgreSQL dialect. Your app will try to initialize the objects by reading/creating sequences, but Redshift does not support sequences.
I am not sure what you're trying to achieve, but I don't think it's a good idea to have an ORM mapping over Redshift DB (probably that's why there's no Hibernate dialect for Redshift).

Related

Getting error while attempting to connect to H2 database in SpringBoot (sts4)

I am a beginner in SpringBoot. I cannot establish the connection to the H2 database and insert the data.
pom.xml
<?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.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springbootproject1</groupId>
<artifactId>springboot-web1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-web1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-security</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
spring.h2.console.enabled=true
spring.security.user.name=username
spring.security.user.password=password
logging.level.org.springframework=info
management.info.env.enabled=true
management.endpoints.web.exposure.include=*
spring.jpa.defer-datasource-initialization=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.driverClassName=org.h2.Driver
The main class
#SpringBootApplication
//#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class SpringbootWeb1Application {
public static void main(String[] args) {
SpringApplication.run(SpringbootWeb1Application.class, args);
}
}
The error is as follows when run in info mode.
2022-08-27 20:04:54.413 INFO 8632 --- [ restartedMain] c.s.s.SpringbootWeb1Application : Starting SpringbootWeb1Application using Java 1.8.0_251 on DESKTOP-6U5SNIB with PID 8632 (C:\Users\User\Downloads\springboot-web1\springboot-web1\target\classes started by User in C:\Users\User\Downloads\springboot-web1\springboot-web1)
2022-08-27 20:04:54.414 INFO 8632 --- [ restartedMain] c.s.s.SpringbootWeb1Application : No active profile set, falling back to 1 default profile: "default"
2022-08-27 20:04:54.449 INFO 8632 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-08-27 20:04:54.449 INFO 8632 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-08-27 20:04:55.084 INFO 8632 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-08-27 20:04:55.114 INFO 8632 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 24 ms. Found 1 JPA repository interfaces.
2022-08-27 20:04:55.565 INFO 8632 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-08-27 20:04:55.571 INFO 8632 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-08-27 20:04:55.571 INFO 8632 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-27 20:04:55.619 INFO 8632 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-08-27 20:04:55.620 INFO 8632 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1171 ms
2022-08-27 20:04:55.807 INFO 8632 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-08-27 20:04:55.883 INFO 8632 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-08-27 20:04:55.890 INFO 8632 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:a58a1162-8ec8-498e-a310-1f2325e399e8'
2022-08-27 20:04:56.017 INFO 8632 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-08-27 20:04:56.045 INFO 8632 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-08-27 20:04:56.123 INFO 8632 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-08-27 20:04:56.182 INFO 8632 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-08-27 20:04:56.500 INFO 8632 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-08-27 20:04:56.506 INFO 8632 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-08-27 20:04:56.564 WARN 8632 --- [ 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-08-27 20:04:57.657 WARN 8632 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/User/Downloads/springboot-web1/springboot-web1/target/classes/data.sql]: create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create sequence user_details_seq start with 1 increment by 50 [*]create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) )"; SQL statement:
create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ) [42000-214]
2022-08-27 20:04:57.660 INFO 8632 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-08-27 20:04:57.660 INFO 8632 --- [ restartedMain] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2022-08-27 20:04:57.873 WARN 8632 --- [ restartedMain] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-214]
2022-08-27 20:04:57.873 INFO 8632 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-08-27 20:04:57.875 INFO 8632 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2022-08-27 20:04:57.876 INFO 8632 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-08-27 20:04:57.888 INFO 8632 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-27 20:04:57.910 ERROR 8632 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/User/Downloads/springboot-web1/springboot-web1/target/classes/data.sql]: create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create sequence user_details_seq start with 1 increment by 50 [*]create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) )"; SQL statement:
create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ) [42000-214]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) [spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.3.jar:2.7.3]
at com.springbootproject1.springbootweb1.SpringbootWeb1Application.main(SpringbootWeb1Application.java:14) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.7.3.jar:2.7.3]
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/User/Downloads/springboot-web1/springboot-web1/target/classes/data.sql]: create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create sequence user_details_seq start with 1 increment by 50 [*]create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) )"; SQL statement:
create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ) [42000-214]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:282) ~[spring-jdbc-5.3.22.jar:5.3.22]
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:254) ~[spring-jdbc-5.3.22.jar:5.3.22]
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:54) ~[spring-jdbc-5.3.22.jar:5.3.22]
at org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer.runScripts(DataSourceScriptDatabaseInitializer.java:90) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.runScripts(AbstractScriptDatabaseInitializer.java:145) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.applyScripts(AbstractScriptDatabaseInitializer.java:107) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.applyDataScripts(AbstractScriptDatabaseInitializer.java:101) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.initializeDatabase(AbstractScriptDatabaseInitializer.java:76) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.boot.sql.init.AbstractScriptDatabaseInitializer.afterPropertiesSet(AbstractScriptDatabaseInitializer.java:65) ~[spring-boot-2.7.3.jar:2.7.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.22.jar:5.3.22]
... 23 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create sequence user_details_seq start with 1 increment by 50 [*]create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) )"; SQL statement:
create sequence user_details_seq start with 1 increment by 50 create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) ) [42000-214]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:502) ~[h2-2.1.214.jar:2.1.214]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) ~[h2-2.1.214.jar:2.1.214]
at org.h2.message.DbException.get(DbException.java:223) ~[h2-2.1.214.jar:2.1.214]
at org.h2.message.DbException.get(DbException.java:199) ~[h2-2.1.214.jar:2.1.214]
at org.h2.message.DbException.getSyntaxError(DbException.java:247) ~[h2-2.1.214.jar:2.1.214]
at org.h2.command.Parser.getSyntaxError(Parser.java:898) ~[h2-2.1.214.jar:2.1.214]
at org.h2.command.Parser.prepareCommand(Parser.java:572) ~[h2-2.1.214.jar:2.1.214]
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:631) ~[h2-2.1.214.jar:2.1.214]
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:554) ~[h2-2.1.214.jar:2.1.214]
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1116) ~[h2-2.1.214.jar:2.1.214]
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:237) ~[h2-2.1.214.jar:2.1.214]
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223) ~[h2-2.1.214.jar:2.1.214]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-4.0.3.jar:na]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:261) ~[spring-jdbc-5.3.22.jar:5.3.22]
... 33 common frames omitted
Also, when I try to view H2 database using http://localhost:8080/h2-console , I get the error "This site can't be reached. localhost refused to connect."
Your data.sql file not correctly executed. Because your file includes multiple sql statement. When I check from the error log, your file includes 2 statements:
create sequence user_details_seq start with 1 increment by 50;
create table user_details ( id integer not null, birthDate timestamp, name varchar(255), primary key (id) );
Every statements must be separated ; symbol.
Please try to separate each of your statements this way.

How to configure a Spring Boot project correctly to work with Quartz and MySQL?

What I did is:
Created a Spring Boot (v2.1.8) Gradle project with Web, JPA, MySQL and Quartz as dependencies.
Then Added following properties on application.properties file
spring.application.name=QuartzTestWithMySQL
server.port=8081
## Data source
#docker run -d --rm -p 3306:3306 --name=mysql-docker -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=test -e MYSQL_PASSWORD=test -e MYSQL_DATABASE=testDB mysql:latest
spring.datasource.name = myDS
spring.datasource.url=jdbc:mysql://localhost:3306/testDB
spring.datasource.username=test
spring.datasource.password=test
## Hibernate Properties
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = create-drop
## QuartzProperties
#spring.quartz.job-store-type=memory
spring.quartz.job-store-type=jdbc
spring.quartz.properties.org.quartz.threadPool.threadCount=5
#spring.quartz.jdbc.initialize-schema=always
#spring.quartz.properties.org.quartz.scheduler.instanceName = MyScheduler
#spring.quartz.properties.org.quartz.threadPool.threadCount = 3
#spring.quartz.properties.org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
spring.quartz.properties.org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#spring.quartz.properties.org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
spring.quartz.properties.org.quartz.jobStore.tablePrefix = QRTZ_
spring.quartz.properties.org.quartz.jobStore.dataSource = myDS
build.gradle file is:
plugins {
id 'org.springframework.boot' version '2.1.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.onssoftware'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Then created following job class:
public class Bismillah implements Job {
#Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("Assalamu Alaikum");
}
}
Then created a controller like:
#RestController
public class SchedulerTestController {
#Autowired
private Scheduler scheduler;
#GetMapping("/scheduler")
public void testScheduler() throws SchedulerException {
// Grab the Scheduler instance from the Factory
//Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
// and start it off
//scheduler.start();
JobDetail job = JobBuilder.newJob(Bismillah.class)
.withIdentity("job1", "group1")
.storeDurably()
.withDescription("Bismillah hir rahmanir rahim")
.build();
CronTrigger cronTrigger = TriggerBuilder.newTrigger()
.withIdentity("trigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("* * 11 * * ?"))
.forJob("job1", "group1")
.build();
scheduler.scheduleJob(job, cronTrigger);
}
}
Then I call from browser following url:
http://localhost:8081/scheduler
to schedule the job.
What I am getting is:
2019-09-18 12:55:31.445 INFO 10507 --- [ main] c.o.Q.QuartzTestWithMySqlApplication : No active profile set, falling back to default profiles: default
2019-09-18 12:55:32.326 INFO 10507 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-18 12:55:32.359 INFO 10507 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 18ms. Found 0 repository interfaces.
2019-09-18 12:55:32.810 INFO 10507 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$7395a7a2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-18 12:55:33.198 INFO 10507 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-09-18 12:55:33.235 INFO 10507 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-18 12:55:33.235 INFO 10507 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-18 12:55:33.344 INFO 10507 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-18 12:55:33.344 INFO 10507 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1841 ms
2019-09-18 12:55:33.545 INFO 10507 --- [ main] com.zaxxer.hikari.HikariDataSource : myDS - Starting...
2019-09-18 12:55:34.179 INFO 10507 --- [ main] com.zaxxer.hikari.HikariDataSource : myDS - Start completed.
2019-09-18 12:55:34.269 INFO 10507 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-09-18 12:55:34.344 INFO 10507 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.11.Final}
2019-09-18 12:55:34.345 INFO 10507 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-09-18 12:55:34.502 INFO 10507 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-09-18 12:55:34.682 INFO 10507 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-18 12:55:34.763 INFO 10507 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
2019-09-18 12:55:35.033 INFO 10507 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#2007435e'
2019-09-18 12:55:35.039 INFO 10507 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-18 12:55:35.596 INFO 10507 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-18 12:55:35.764 WARN 10507 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : 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
2019-09-18 12:55:36.509 WARN 10507 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration$JdbcStoreTypeConfiguration$QuartzSchedulerDependencyConfiguration': Unexpected exception during bean creation; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2019-09-18 12:55:36.518 INFO 10507 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2019-09-18 12:55:36.520 INFO 10507 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-09-18 12:55:36.522 INFO 10507 --- [ main] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2019-09-18 12:55:36.541 INFO 10507 --- [ main] com.zaxxer.hikari.HikariDataSource : myDS - Shutdown initiated...
2019-09-18 12:55:36.553 INFO 10507 --- [ main] com.zaxxer.hikari.HikariDataSource : myDS - Shutdown completed.
2019-09-18 12:55:36.561 INFO 10507 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-09-18 12:55:36.592 INFO 10507 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-18 12:55:36.613 ERROR 10507 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration$JdbcStoreTypeConfiguration$QuartzSchedulerDependencyConfiguration': Unexpected exception during bean creation; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:528) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at com.onssoftware.QuartzTestWithMySQL.QuartzTestWithMySqlApplication.main(QuartzTestWithMySqlApplication.java:10) [classes/:na]
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_201]
at java.lang.reflect.Executable.declaredAnnotations(Executable.java:599) ~[na:1.8.0_201]
at java.lang.reflect.Executable.declaredAnnotations(Executable.java:597) ~[na:1.8.0_201]
at java.lang.reflect.Executable.getAnnotation(Executable.java:570) ~[na:1.8.0_201]
at java.lang.reflect.Method.getAnnotation(Method.java:622) ~[na:1.8.0_201]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.lambda$determineCandidateConstructors$0(AutowiredAnnotationBeanPostProcessor.java:249) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:410) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:417) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:389) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:248) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1269) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1184) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 14 common frames omitted
Process finished with exit code 1
I think your error related to the following issue
/spring-boot/issues/18153
You could try to downgrade spring-boot to 2.1.7.RELEASE:
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
...
}

spring-boot-starter-quartz jdbc example

Starting with spring-boot 2.x.x they started offering spring-boot-starter-quartz which is great! Out of the box it does an in-memory store. I want to change it to be a clustered environment but I'm having issues with the configuration I think mostly because I need to put the qrtz_ tables in a different schema than my default data source. Does anyone have an example of using an alternate datasource? I'm currently attempting to set the properties field (as you can see below) but its like they are not being picked up by the configuration bean. Any help is appreciated.
Configuration
spring:
quartz:
job-store-type: jdbc
jdbc:
initialize-schema: never
properties:
scheduler:
instanceName : MyClusteredScheduler
instanceId : AUTO
threadPool:
class : org.quartz.simpl.SimpleThreadPool
threadCount : 25
threadPriority : 5
jobStore:
misfireThreshold : 60000
class : org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass : org.quartz.impl.jdbcjobstore.StdJDBCDelegate
useProperties : false
dataSource : myDS
tablePrefix : QRTZ_
isClustered : true
clusterCheckinInterval : 20000
dataSource:
myDS:
driver : com.mysql.jdbc.Driver
URL : jdbc:mysql://127.0.0.1:3306/quartz
user : removed
password : removed
maxConnections : 5
validationQuery : select 0 from dual
Output from log
2017-11-06 13:33:02.853 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.0 created.
2017-11-06 13:33:02.856 INFO 7082 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : Using db table-based data access locking (synchronization).
2017-11-06 13:33:02.858 INFO 7082 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : JobStoreCMT initialized.
2017-11-06 13:33:02.859 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.0) 'quartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is not clustered.
2017-11-06 13:33:02.859 INFO 7082 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
2017-11-06 13:33:02.860 INFO 7082 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 2.3.0
2017-11-06 13:33:02.860 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : JobFactory set to: org.springframework.boot.autoconfigure.quartz.AutowireCapableBeanJobFactory#21132086
2017-11-06 13:33:03.214 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-11-06 13:33:03.216 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2017-11-06 13:33:03.223 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2017-11-06 13:33:03.227 INFO 7082 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2017-11-06 13:33:03.227 INFO 7082 --- [ main] o.s.s.quartz.SchedulerFactoryBean : Starting Quartz Scheduler now
2017-11-06 13:33:05.250 WARN 7082 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
2017-11-06 13:33:05.250 INFO 7082 --- [ main] o.s.s.quartz.SchedulerFactoryBean : Shutting down Quartz Scheduler
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED shutting down.
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED paused.
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED shutdown complete.
2017-11-06 13:33:05.252 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2017-11-06 13:33:05.253 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2017-11-06 13:33:05.254 INFO 7082 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-11-06 13:33:05.255 INFO 7082 --- [ main] com.zaxxer.hikari.HikariDataSource : testdb - Shutdown initiated...
2017-11-06 13:33:05.264 INFO 7082 --- [ main] com.zaxxer.hikari.HikariDataSource : testdb - Shutdown completed.
2017-11-06 13:33:05.265 INFO 7082 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-11-06 13:33:05.283 INFO 7082 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-06 13:33:05.293 ERROR 7082 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:186) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:358) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:159) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:884) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at com.tci.reader.incident.parser.IncidentParserApplication.main(IncidentParserApplication.java:18) [classes/:na]
Caused by: org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.start(SchedulerFactoryBean.java:738) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 14 common frames omitted
Caused by: org.quartz.SchedulerConfigException: Failure occured during job recovery.
at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:697) ~[quartz-2.3.0.jar:na]
at org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:539) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.StdScheduler.start(StdScheduler.java:142) ~[quartz-2.3.0.jar:na]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.startScheduler(SchedulerFactoryBean.java:664) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.start(SchedulerFactoryBean.java:735) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 15 common frames omitted
Caused by: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:157) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.DBSemaphore.obtainLock(DBSemaphore.java:113) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3842) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.recoverJobs(JobStoreSupport.java:839) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:695) ~[quartz-2.3.0.jar:na]
... 19 common frames omitted
Caused by: java.sql.SQLException: No database selected
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-2.7.2.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-2.7.2.jar:na]
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:96) ~[quartz-2.3.0.jar:na]
... 23 common frames omitted
You have to use the correct properties for the quartz properties.
Your properties are missing ...org.quartz...
For the none-yml notation, try this for the threadCount:
spring.quartz.properties.org.quartz.threadPool.threadCount=25
For the yml notation:
Add two layers under the 'properties', e.g.
spring:
quartz:
properties:
org:
quartz:
threadPool:
threadCount : 25
Application.yml file:
spring:
jpa:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://127.0.0.1:3306/Quartz
username: Your Username
password: Your Password
quartz:
scheduler:
instanceName: Scheduler
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 3
context:
key:
QuartzTopic: QuartzPorperties
jobStore:
driver: com.mysql.jdbc.Driver
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
misfireThreshold: 6000
tablePrefix: QRTZ_
Next create a Configuration class which reads these properties from the yml file and then creates a Scheduler Bean:
#Configuration
public class SchedulerConfig {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
#Value("${quartz.scheduler.instanceName}")
private String instanceName;
#Value("${quartz.threadPool.class}")
private String threadClass;
#Value("${quartz.threadPool.threadCount}")
private String threadCount;
#Value("${quartz.context.key.QuartzTopic}")
private String quartzTopic;
#Value("${quartz.jobStore.class}")
private String jobStoreClass;
#Value("${quartz.jobStore.driverDelegateClass}")
private String driverDelegateClass;
#Value("${quartz.jobStore.misfireThreshold}")
private String misfireThreshold;
#Value("${quartz.jobStore.tablePrefix}")
private String tablePrefix;
#Value("${quartz.jobStore.driver}")
private String dataSourceDriver;
#Value("${spring.datasource.url}")
private String dataSourceUrl;
#Value("${spring.datasource.username}")
private String dataSourceUsername;
#Value("${spring.datasource.password}")
private String databasePassword;
#Bean({"Scheduler"})
public Scheduler getScheduler() {
Scheduler scheduler = null;
try {
StdSchedulerFactory factory = new StdSchedulerFactory();
Properties props = new Properties();
props.put("org.quartz.scheduler.instanceName", instanceName);
props.put("org.quartz.threadPool.class", threadClass);
props.put("org.quartz.threadPool.threadCount", threadCount);
props.put("org.quartz.context.key.QuartzTopic", quartzTopic);
props.put("org.quartz.jobStore.class", jobStoreClass);
props.put("org.quartz.jobStore.driverDelegateClass", driverDelegateClass);
props.put("quartz.jobStore.misfireThreshold", misfireThreshold);
props.put("org.quartz.jobStore.tablePrefix", tablePrefix);
props.put("org.quartz.jobStore.dataSource", "myDS");
props.put("org.quartz.dataSource.myDS.driver", dataSourceDriver);
props.put("org.quartz.dataSource.myDS.URL", dataSourceUrl);
props.put("org.quartz.dataSource.myDS.user", dataSourceUsername);
props.put("org.quartz.dataSource.myDS.password", databasePassword);
props.put("org.quartz.dataSource.myDS.maxConnections", "10");
factory.initialize(props);
scheduler = factory.getScheduler();
scheduler.start();
scheduler.resumeAll(); // This is to resume the entire scheduler when a new build is deployed
} catch (Exception e) {
logger.error("{} - SchedulerConfig class - getScheduler() - Error creating Scheduler instance: {}",
appName, e);
}
return scheduler;
}
}
Finally, use the Bean as below in any class you want:
#Autowired
private Scheduler scheduler;

Spring Bean Not loaded and injected in JAAS

I am trying to load the Spring UserRepository to my LoginModule but container is not loading it. To me it seems LoginContext is loading the LoginModule by dynamic loading using the config file provided to LoginContext. As this is loaded by JVM seems container is therefore ignoring LoginModule although I have tried #Component, #Service, #Configurable annotations, kindly help.
JUnit Test
#RunWith(SpringRunner.class)
#SpringBootTest
#Transactional
#ComponentScan("com.kashtech.jaas")
public class JaasLoginModuleTests {
...
#Before
public void initialize() {
System.setProperty("java.security.auth.login.config", "ebay-manager-jaas.config");
try {
lc = new LoginContext("EbayManagerLoginModule", new JaasCallBackHandler("test", "test"));
} catch (LoginException e) {
e.printStackTrace();
}
}
#Test
public void testLogin() {
try {
lc.login();
} catch (LoginException le) {
log.error("Error whilst testing login : " + le.getMessage());
}
}
LoginModule
import com.kashtech.jaas.repository.mongodb.UserRepository;
public class JaasLoginModule implements LoginModule {
#Inject
private UserRepository userRepository;
....
//find user from DB
dbUser = findUserFromDB(username);
public User findUserFromDB(String username) {
User u = userRepository.findByUsername(username);
return u;
}
}
ApplicationConfiguration
#SpringBootApplication
#ComponentScan("com.kashtech.jaas")
#EnableMongoRepositories(basePackages = "com.kashtech.jaas.repository.mongodb")
public class JaasSystemApplication {
public static void main(String[] args) {
SpringApplication.run(JaasSystemApplication.class, args);
}
}
Repository
import org.springframework.data.mongodb.repository.MongoRepository;
import com.kashtech.jaas.domain.User;
public interface UserRepository extends MongoRepository<User, String>{
public User findByUsername(String username);
}
DataSourceConfig
#Configuration
#EnableJpaRepositories("com.kashtech.jaas.repository")
#EnableTransactionManagement
public class DatasourceConfig implements EnvironmentAware {
private RelaxedPropertyResolver mongoDBResolver;
#Bean
public Mongo mongo() throws Exception {
return new MongoClient(mongoDBResolver.getProperty("host", mongoDBResolver.getProperty("port")));
}
#Bean
public MongoTemplate mongoTemplate() throws Exception {
try {
log.info("##################### Configuring Mongo DataSource ####################");
log.info("Host : " + mongoDBResolver.getProperty("host"));
log.info("Port : " + mongoDBResolver.getProperty("port"));
log.info("Database : " + mongoDBResolver.getProperty("database"));
log.info("#######################################################################");
} catch (Exception e) {
log.error("Database Connection Error ... Check the configurations.");
}
return new MongoTemplate(mongo(), mongoDBResolver.getProperty("database"));
}
Stacktrace
2017-04-28 19:19:56.551 INFO 7592 --- [ main] com.kashtech.JaasLoginModuleTests : Starting JaasLoginModuleTests on Panther with PID 7592 (started by kashif in C:\Development\workspaces\jaas-system)
2017-04-28 19:19:56.551 INFO 7592 --- [ main] com.kashtech.JaasLoginModuleTests : The following profiles are active: Dev
2017-04-28 19:19:56.578 INFO 7592 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#1757cd72: startup date [Fri Apr 28 19:19:56 BST 2017]; root of context hierarchy
2017-04-28 19:19:56.905 INFO 7592 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2017-04-28 19:19:56.924 INFO 7592 --- [ main] .RepositoryConfigurationExtensionSupport : Spring Data JPA - Could not safely identify store assignment for repository candidate interface com.kashtech.jaas.repository.mongodb.UserRepository.
2017-04-28 19:19:56.931 INFO 7592 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2017-04-28 19:19:56.982 INFO 7592 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'mongo' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=datasourceConfig; factoryMethodName=mongo; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/kashtech/jaas/config/DatasourceConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; factoryMethodName=mongo; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]]
2017-04-28 19:19:57.190 INFO 7592 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-04-28 19:19:57.359 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : ##################### Configuring DataSource #####################
2017-04-28 19:19:57.359 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Driver class : com.mysql.jdbc.Driver
2017-04-28 19:19:57.359 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Driver URL : jdbc:mysql://localhost/ebay-manager
2017-04-28 19:19:57.359 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Driver username : root
2017-04-28 19:19:57.360 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Driver password : admin
2017-04-28 19:19:57.480 INFO 7592 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-04-28 19:19:57.499 INFO 7592 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-04-28 19:19:57.573 INFO 7592 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2017-04-28 19:19:57.575 INFO 7592 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2017-04-28 19:19:57.576 INFO 7592 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2017-04-28 19:19:57.618 INFO 7592 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Fri Apr 28 19:19:57 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Fri Apr 28 19:19:58 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2017-04-28 19:19:58.159 INFO 7592 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-04-28 19:19:58.440 WARN 7592 --- [ main] o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : none. Supported values include create, create-drop, update, and validate. Ignoring
2017-04-28 19:19:58.556 INFO 7592 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-04-28 19:19:58.575 INFO 7592 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-04-28 19:19:58.575 INFO 7592 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2017-04-28 19:19:58.585 INFO 7592 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-04-28 19:19:58.596 WARN 7592 --- [ main] o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : none. Supported values include create, create-drop, update, and validate. Ignoring
2017-04-28 19:19:58.602 WARN 7592 --- [ main] o.h.j.i.EntityManagerFactoryRegistry : HHH000436: Entity manager factory name (default) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
2017-04-28 19:19:58.602 INFO 7592 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-04-28 19:19:58.646 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : ##################### Configuring Mongo DataSource ####################
2017-04-28 19:19:58.646 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Host : 127.0.0.1
2017-04-28 19:19:58.646 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Port : 27017
2017-04-28 19:19:58.646 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : Database : ebay-manager
2017-04-28 19:19:58.646 INFO 7592 --- [ main] c.kashtech.jaas.config.DatasourceConfig : #######################################################################
2017-04-28 19:19:59.212 INFO 7592 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2017-04-28 19:19:59.212 INFO 7592 --- [ main] org.mongodb.driver.cluster : Adding discovered server 127.0.0.1:27017 to client view of cluster
2017-04-28 19:19:59.309 INFO 7592 --- [127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:18}] to 127.0.0.1:27017
2017-04-28 19:19:59.311 INFO 7592 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=127.0.0.1:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 2]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=613444}
2017-04-28 19:19:59.312 INFO 7592 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Discovered cluster type of STANDALONE
2017-04-28 19:19:59.453 INFO 7592 --- [ main] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:19}] to 127.0.0.1:27017
2017-04-28 19:19:59.915 INFO 7592 --- [ main] com.kashtech.JaasLoginModuleTests : Started JaasLoginModuleTests in 3.67 seconds (JVM running for 4.403)
2017-04-28 19:20:00.035 INFO 7592 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext#103f852 testClass = JaasLoginModuleTests, testInstance = com.kashtech.JaasLoginModuleTests#44a3ec6b, testMethod = testLogin#JaasLoginModuleTests, testException = [null], mergedContextConfiguration = [MergedContextConfiguration#587c290d testClass = JaasLoginModuleTests, locations = '{}', classes = '{class com.kashtech.JaasSystemApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer#14acaea5, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer#59fa1d9b, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer#0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer#0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer#77cd7a0], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager#60c8a093]; rollback [true]
2017-04-28 19:20:00.065 INFO 7592 --- [ main] com.kashtech.JaasLoginModuleTests : Callback Handler invoked
test
2017-04-28 19:20:00.068 ERROR 7592 --- [ main] com.kashtech.JaasLoginModuleTests : Error whilst testing login : java.lang.NullPointerException
at com.kashtech.jaas.domain.JaasLoginModule.findUserFromDB(JaasLoginModule.java:307)
at com.kashtech.jaas.domain.JaasLoginModule.login(JaasLoginModule.java:146)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.security.auth.login.LoginContext.invoke(Unknown Source)
at javax.security.auth.login.LoginContext.access$000(Unknown Source)
at javax.security.auth.login.LoginContext$4.run(Unknown Source)
at javax.security.auth.login.LoginContext$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(Unknown Source)
at javax.security.auth.login.LoginContext.login(Unknown Source)
at com.kashtech.JaasLoginModuleTests.testLogin(JaasLoginModuleTests.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
2017-04-28 19:20:00.077 INFO 7592 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test context [DefaultTestContext#103f852 testClass = JaasLoginModuleTests, testInstance = com.kashtech.JaasLoginModuleTests#44a3ec6b, testMethod = testLogin#JaasLoginModuleTests, testException = java.lang.NullPointerException, mergedContextConfiguration = [MergedContextConfiguration#587c290d testClass = JaasLoginModuleTests, locations = '{}', classes = '{class com.kashtech.JaasSystemApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer#14acaea5, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer#59fa1d9b, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer#0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer#0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer#77cd7a0], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]].
2017-04-28 19:20:00.086 INFO 7592 --- [ Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#1757cd72: startup date [Fri Apr 28 19:19:56 BST 2017]; root of context hierarchy
2017-04-28 19:20:00.089 INFO 7592 --- [ Thread-3] org.mongodb.driver.connection : Closed connection [connectionId{localValue:2, serverValue:19}] to 127.0.0.1:27017 because the pool has been closed.
2017-04-28 19:20:00.091 INFO 7592 --- [ Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
You're calling new which init's the class outside of the IoC container and thus spring cannot inject into it. Autowire the class into the unit test. Your JaasLoginModule needs to be defined as a Bean, Component, Service and then autowired to the test class.

Gracefull shutdown for Spring boot Application

I am running a spring-boot application and everything is good except when i try to close it. I got error on the below code
while (true) {
try {
if(level2List == null)
break;
CDR cdr = level2List.poll(2, TimeUnit.SECONDS);
The error is generated on the last line , spring boot is shutting down level2List before the 2 second wait is done as below
2015-05-29 17:32:15.758 INFO 27390 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#358ee631: startup date [Fri May 29 17:31:17 GMT 2015]; root of context hierarchy
2015-05-29 17:32:15.765 INFO 27390 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2015-05-29 17:32:15.766 INFO 27390 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2015-05-29 17:32:15.780 INFO 27390 --- [ Thread-1] o.s.c.ehcache.EhCacheManagerFactoryBean : Shutting down EhCache CacheManager
2015-05-29 17:32:15.804 INFO 27390 --- [ Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'level2ES'
2015-05-29 17:32:15.815 INFO 27390 --- [ Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'level1ES'
2015-05-29 17:32:15.823 INFO 27390 --- [ Thread-1] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2015-05-29 17:32:15.825 INFO 27390 --- [ Thread-1] com.jolbox.bonecp.BoneCP : Shutting down connection pool...
2015-05-29 17:32:15.833 INFO 27390 --- [ Thread-1] com.jolbox.bonecp.BoneCP : Connection pool has been shutdown.
2015-05-29 17:32:15.848 ERROR 27390 --- [pool-2-thread-1] c.t.t.c.process.CDRDataBase : Error
java.lang.InterruptedException: null
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2088)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at com.teltacworldwide.tekram.cdrserver.process.CDRDataBaseNative.run(CDRDataBaseNative.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Is there any way to order the shutting down process or to make sure I am not using level2List before shutting it down?
BR
Shahbour
I did two things
add
#Bean(destroyMethod = "shutdown")
public ThreadPoolTaskExecutor level1ES() {
also
} catch (InterruptedException e) {
log.warn("Closing application while CDR still in queue"); }
BR
Shahbour

Resources