Spring Batch does not run when importing H2 SQL scripts - spring

I am trying to run a Spring Batch application to create batch jobs.
My application.properties as shown below:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:localhost;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=admin
spring.datasource.password=p#ssw0rd
spring.datasource.schema=schema-hsqldb.sql
The error I am getting is shown below:
Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException: Property spring.datasource.schema with value 'class path resource [schema-hsqldb.sql]' is invalid: The specified resource does not exist.
As far as I know, the schema-hsqldb.sql exists in classpath /org/springframework/batch/core/schema-hsqldb.sql.
The Spring boot application works when I commented out spring.datasource.schema=schema-hsqldb.sql. Do I have to manually import the SQL scripts? If so, how do I do that?

Your issue is that you are using the H2 driver with the schema of HSQL. H2 and HSQL are different products. You need to use the schema of H2 as well:
spring.datasource.schema=/org/springframework/batch/core/schema-h2.sql
That said, you don't really need to configure the datasource for embedded databases with Spring Boot, the datasource will be automatically configured. Here is an excerpt from the Embedded Database Support section of the reference docs:
Spring Boot can auto-configure embedded H2, HSQL, and Derby databases. You need not provide any connection URLs. You need only include a build dependency to the embedded database that you want to use.

Related

Get NoInitialContext Spring Boot 2.0.x Embedded Tomcat Resource and DataSource Configuration Using JavaConfig

Following other links I have tried all configurations including enabling jndi of embedded tomcat container. (A very good detailed like is: https://www.roytuts.com/spring-boot-jndi-datasource/) But the problem is that the DataSource is looked up against JNDI and I get follwoing exception:
Please note that From Spring 2.0.x Embedded configuration classes have changed.
Get:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial.
As for the question of JNDI lookup in Embedded tomcat is rare use case I am trying to simulate and reproduce a Database Connection Pooling Error in production and for that I have to use JavaConfig settings for Resource and DataSource both.

Spring boot datasource specific properties for embedded jetty server

I have spring boot application and it's basically a gradle project, so, I have below dependency added in my gradle file:
org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE
Application gets deployed in embedded jetty server. I have following set of properties in application.properties for db connection polling:
spring.datasource.driver-class-name
spring.datasource.max-active
spring.datasource.max-idle
spring.datasource.min-idle
spring.datasource.validation-query
spring.datasource.name
I was referring to below two links:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Configuration-Changelog
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.5-Configuration-Changelog
I came to know that some of the datasource properties which used in application.properties file in my application are removed starting sprint boot version 1.4 but issue they haven't mentioned what are the new properties to use. Like for tomcat server they have provided all set of properties but not for jetty server. I am facing some db related errors like 'too many connections' after my application run for sometime, my assumption is that datasource props I am currently using are not correct and should be replaced with correct values, but unfortunately I am unable to find correct property names.
Jetty doesn't have its own Pooling DataSource implementation. You can include HikariCP in your project and customise using the spring.datasource.hikari.* properties. With each property matching the bean properties that can be set on Hikari's datasource implementation.

Spring Boot JPA with not a well known database

I am trying to write Spring Boot application to connect to a Teiid database, I want to use JPA layer on it. I have configured the JDBC Data Source, but since this not well-known database in Spring JPA libraries do not autodetect this source. I have manually setup "spring.jpa.*" properties too. I do have a Hibernate dialect for this database, and it is on the classpath.
So, how does one need to configure JPA layer for a not well-known database in Spring Boot? Thank you for your time.
Ramesh..
This is fairly well defined in the Spring Boot documentation.
You can set this explicitly in the application.properties file
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Migrating database in spring application

In spring integrated hibernated application,I need to change the database from sql server to oracle without code change ?
If you really just want to change the datasource
have a look at the documentation here Spring Documentation for Oracle JDBC
You need to change your datasource that you use to point to Oracle.
Import the JDBC dependency for the Oracle JDBC connector as a dependency
Configure Hibernate to use the correct dialect
e.g. oracle.jdbc.driver.OracleDriver
Don't know how you configure your environment, but that should get you started.

Petclinic hibernate.dialect for HSQL

I am trying to understand Spring Petclinic Application.
By default it seems that HSQL database and JPA is used, but I am unableto to find where the Hibernate Dialect for HSQL is mentioned in the application.
I understand that it is a mandatory property for Hibernate.
Kindly suggest
What about where org.hibernate.dialect.HSQLDialect and where the driver is org.hsqldb.jdbcDriver. Normally, if this is a Spring application, this will be present in an applicationContext.xml or tx-datasource.xml configuration file. Whatever is the case, these properties must be in one of the XML Spring configuration files. Of course, they may be in a Java class (an alternative), but in most applications, they are present in Spring XML files where the dataSource bean is defined. Usually, in web applications, that would be in directory under /WEB-INF or /webapp/WEB-INF.

Resources