Spring Batch takes one minute before termination - java

After the completion of my Spring Batch job, it takes about one minute till the shutdown hook is launched.
As I am still learning how to use the framework, I am quite sure I misconfigured something.
My job and step is straightforward: read data from a database and write it back in another table.
#Bean
public Job importUserJob(Step step1)
{
return jobBuilderFactory.get("importUserJob")
.incrementer(new RunIdIncrementer())
.flow(step1)
.end()
.build();
}
#Bean
public Step step1(JdbcCursorItemReader<User> reader, SaveAllRepositoryItemWriter<User> writer)
{
return stepBuilderFactory.get("step1")
.<User, User> chunk(1000)
.reader(reader)
.writer(writer)
.build();
}
SaveAllRepositoryItemWriter is a simplified version of RepositoryItemWriter, which takes a CrudRepository and calls CrudRepository.saveAll() in it's write()-method (see below).
The last lines of the log output is as follows:
2020-05-28 10:53:57.213 INFO 5964 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{run.id=23}]
2020-05-28 10:53:57.264 INFO 5964 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
2020-05-28 10:53:57.643 WARN 5964 --- [ main] c.n.d.SaveAllRepositoryItemWriter : Writing finished
2020-05-28 10:53:57.664 INFO 5964 --- [ main] o.s.batch.core.step.AbstractStep : Step: [step1] executed in 400ms
2020-05-28 10:53:57.676 INFO 5964 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] completed with the following parameters: [{run.id=23}] and the following status: [COMPLETED] in 441ms
2020-05-28 10:54:57.002 INFO 5964 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-05-28 10:54:57.004 INFO 5964 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-05-28 10:54:57.004 INFO 5964 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-05-28 10:54:57.006 INFO 5964 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
I added the log output Writing finished to ensure that the Writer has actually written the data, as I have seen here that it might be a problem.
If I did not provide enough information, I am happy to provide more information.
public class SaveAllRepositoryItemWriter<T> implements ItemWriter<T>, InitializingBean
{
private CrudRepository<T, ?> repository;
protected static final Log logger = LogFactory.getLog(SaveAllRepositoryItemWriter.class);
public void setRepository(CrudRepository<T, ?> repository)
{
this.repository = repository;
}
/**
* Check mandatory properties - there must be a repository.
*/
#Override
public void afterPropertiesSet() throws Exception
{
Assert.state(repository != null, "A CrudRepository implementation is required");
}
#Override
public void write(List<? extends T> items) throws Exception
{
this.repository.saveAll(items);
logger.warn("Writing finished");
}
}
Debug Log:
2020-05-28 11:27:15.541 DEBUG 9984 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=25, version=3, name=step1, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0
2020-05-28 11:27:15.541 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.updateExecutionContext]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2020-05-28 11:27:15.541 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(1002762002<open>)] for JPA transaction
2020-05-28 11:27:15.541 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#50448409]
2020-05-28 11:27:15.541 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL update
2020-05-28 11:27:15.541 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL statement [UPDATE SPRING_BATCH.BATCH_JOB_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE JOB_EXECUTION_ID = ?]
2020-05-28 11:27:15.547 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-05-28 11:27:15.547 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1002762002<open>)]
2020-05-28 11:27:15.548 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(1002762002<open>)] after transaction
2020-05-28 11:27:15.548 DEBUG 9984 --- [ main] o.s.b.core.job.flow.support.SimpleFlow : Completed state=importUserJob.step1 with status=COMPLETED
2020-05-28 11:27:15.548 DEBUG 9984 --- [ main] o.s.b.core.job.flow.support.SimpleFlow : Handling state=importUserJob.COMPLETED
2020-05-28 11:27:15.548 DEBUG 9984 --- [ main] o.s.b.core.job.flow.support.SimpleFlow : Completed state=importUserJob.COMPLETED with status=COMPLETED
2020-05-28 11:27:15.549 DEBUG 9984 --- [ main] o.s.batch.core.job.AbstractJob : Job execution complete: JobExecution: id=25, version=1, startTime=Thu May 28 09:27:15 UTC 2020, endTime=null, lastUpdated=Thu May 28 09:27:15 UTC 2020, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=25, version=0, Job=[importUserJob]], jobParameters=[{run.id=25}]
2020-05-28 11:27:15.550 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.update]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2020-05-28 11:27:15.550 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(708004780<open>)] for JPA transaction
2020-05-28 11:27:15.550 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#470d183]
2020-05-28 11:27:15.550 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL query
2020-05-28 11:27:15.550 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL statement [SELECT VERSION FROM SPRING_BATCH.BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2020-05-28 11:27:15.551 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL query
2020-05-28 11:27:15.551 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL statement [SELECT COUNT(*) FROM SPRING_BATCH.BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID = ?]
2020-05-28 11:27:15.555 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL update
2020-05-28 11:27:15.555 DEBUG 9984 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing prepared SQL statement [UPDATE SPRING_BATCH.BATCH_JOB_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?]
2020-05-28 11:27:15.556 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-05-28 11:27:15.556 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(708004780<open>)]
2020-05-28 11:27:15.557 DEBUG 9984 --- [ main] o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(708004780<open>)] after transaction
2020-05-28 11:27:15.557 INFO 9984 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] completed with the following parameters: [{run.id=25}] and the following status: [COMPLETED] in 247ms
2020-05-28 11:28:15.069 DEBUG 9984 --- [extShutdownHook] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#13e39c73, started on Thu May 28 09:27:12 UTC 2020
2020-05-28 11:28:15.072 INFO 9984 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-05-28 11:28:15.073 INFO 9984 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-05-28 11:28:15.074 INFO 9984 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-05-28 11:28:15.075 INFO 9984 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Info-Log with around 100'000 items:
2020-05-28 15:01:58.230 INFO 8172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{run.id=5}]
2020-05-28 15:01:58.275 INFO 8172 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
2020-05-28 15:02:03.640 INFO 8172 --- [ main] c.n.d.SaveAllRepositoryItemWriter : Written 10000 items.
2020-05-28 15:02:13.757 INFO 8172 --- [ main] c.n.d.SaveAllRepositoryItemWriter : Written 10000 items.
...
2020-05-28 15:04:24.750 INFO 8172 --- [ main] c.n.d.SaveAllRepositoryItemWriter : Written 8512 items.
2020-05-28 15:04:29.041 INFO 8172 --- [ main] o.s.batch.core.step.AbstractStep : Step: [step1] executed in 2m30s766ms
2020-05-28 15:04:29.065 INFO 8172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] completed with the following parameters: [{run.id=5}] and the following status: [COMPLETED] in 2m30s816ms
2020-05-28 15:04:29.068 INFO 8172 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-05-28 15:04:29.070 INFO 8172 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-05-28 15:04:29.071 INFO 8172 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-05-28 15:04:29.073 INFO 8172 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
application.properties
spring.datasource.url=jdbc:postgresql://some_ip:5432/some_db
spring.datasource.username=user
spring.datasource.password=pw
spring.jpa.properties.hibernate.dialect = org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.jooq.sql-dialect=Postgres
spring.flyway.schemas = my_schema
spring.flyway.default-schema = my_schema
# Write metadata into own schema
# See https://stackoverflow.com/a/62057739/2021763 for an explanation
spring.batch.initialize-schema=always
spring.batch.table-prefix=SPRING_BATCH.BATCH_
spring.batch.schema=classpath:db/create_spring_batch_tables.sql
Dependencies in the pom.xml (omitted test-scope)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

Related

Spring Boot application shutting down immediately after start

I can't figure out why my dockerized Spring Boot application terminates immediately after starting up. I looked into similar issues but couldn't find a reason for mine to fail yet.
The docker image runs ok locally, but when running on Azure Container Apps it does an auto-shutdown.
This is the log with Hikari on debug:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.4)
2022-10-02 23:09:00.444 INFO 1 --- [ main] io.pomatti.app.books.BookApplication : Starting BookApplication v0.0.1-SNAPSHOT using Java 17.0.4.1 on app-books--sw6babs-6db8f449fb-n2pvt with PID 1 (/opt/app/*.jar started by root in /opt/app)
2022-10-02 23:09:00.509 INFO 1 --- [ main] io.pomatti.app.books.BookApplication : No active profile set, falling back to 1 default profile: "default"
2022-10-02 23:09:02.933 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-10-02 23:09:03.111 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 169 ms. Found 1 JPA repository interfaces.
2022-10-02 23:09:04.535 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-10-02 23:09:04.542 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-10-02 23:09:04.542 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-10-02 23:09:04.715 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-10-02 23:09:04.715 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4080 ms
2022-10-02 23:09:04.927 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : Driver class com.microsoft.sqlserver.jdbc.SQLServerDriver found in Thread context class loader TomcatEmbeddedWebappClassLoader
context: ROOT
delegate: true
----------> Parent Classloader:
org.springframework.boot.loader.LaunchedURLClassLoader#28c97a5
2022-10-02 23:09:05.833 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-10-02 23:09:06.014 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.11.Final
2022-10-02 23:09:06.327 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-10-02 23:09:06.617 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : HikariPool-1 - configuration:
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : allowPoolSuspension................................false
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : autoCommit................................true
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : catalog................................none
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : connectionInitSql................................none
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : connectionTestQuery................................none
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : connectionTimeout................................30000
2022-10-02 23:09:06.620 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSource................................none
2022-10-02 23:09:06.621 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSourceClassName................................none
2022-10-02 23:09:06.621 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSourceJNDI................................none
2022-10-02 23:09:06.621 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : dataSourceProperties................................{password=<masked>}
2022-10-02 23:09:06.621 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : driverClassName................................"com.microsoft.sqlserver.jdbc.SQLServerDriver"
2022-10-02 23:09:06.621 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : exceptionOverrideClassName................................none
2022-10-02 23:09:06.621 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : healthCheckProperties................................{}
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : healthCheckRegistry................................none
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : idleTimeout................................600000
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : initializationFailTimeout................................1
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : isolateInternalQueries................................false
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : jdbcUrl................................jdbc:sqlserver://sql-autoscale-2996.database.windows.net:1433;database=sqldb-autoscale-2996;user=dbadmin#sql-autoscale-2996;password=<masked>#777;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : keepaliveTime................................0
2022-10-02 23:09:06.622 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : leakDetectionThreshold................................0
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : maxLifetime................................1800000
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : maximumPoolSize................................10
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : metricRegistry................................none
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : metricsTrackerFactory................................com.zaxxer.hikari.metrics.micrometer.MicrometerMetricsTrackerFactory#5e8a459
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : minimumIdle................................10
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : password................................<masked>
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : poolName................................"HikariPool-1"
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : readOnly................................false
2022-10-02 23:09:06.623 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : registerMbeans................................false
2022-10-02 23:09:06.624 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : scheduledExecutor................................none
2022-10-02 23:09:06.624 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : schema................................none
2022-10-02 23:09:06.624 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : threadFactory................................internal
2022-10-02 23:09:06.624 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : transactionIsolation................................default
2022-10-02 23:09:06.624 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : username................................none
2022-10-02 23:09:06.624 DEBUG 1 --- [ main] com.zaxxer.hikari.HikariConfig : validationTimeout................................5000
2022-10-02 23:09:06.624 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-10-02 23:09:07.726 DEBUG 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:1 ClientConnectionId: 1061c2f8-febf-4f1f-b9f6-86ee6dd22af4
2022-10-02 23:09:07.732 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-10-02 23:09:07.824 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.SQLServer2012Dialect
2022-10-02 23:09:07.832 DEBUG 1 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=1, active=1, idle=0, waiting=0)
2022-10-02 23:09:08.027 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:2 ClientConnectionId: 5035df48-1a77-406f-95b1-99d289e2d70e
2022-10-02 23:09:08.227 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:3 ClientConnectionId: 2f01f8bb-e542-4351-9b5c-dcf7cd6084ef
2022-10-02 23:09:08.411 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:4 ClientConnectionId: fd8950e7-85e8-4ae2-80be-8d88d3a7c84d
2022-10-02 23:09:08.614 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:5 ClientConnectionId: 73205252-2e69-4a7d-b347-9ba7d8e6458f
2022-10-02 23:09:08.737 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:6 ClientConnectionId: 0814ccbd-f55c-4442-925d-be9046619eb5
2022-10-02 23:09:08.921 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:7 ClientConnectionId: f5fb5f48-1c99-4b0c-9b58-828627cfaac2
2022-10-02 23:09:09.119 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:8 ClientConnectionId: 730e1bf3-1e7b-4416-980e-9a64cda711ea
2022-10-02 23:09:09.319 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:9 ClientConnectionId: 23786119-d561-4da6-a59e-08ceb76c7065
2022-10-02 23:09:09.519 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection ConnectionID:10 ClientConnectionId: 9cc6c870-b6a2-4ee3-bc06-14d81bd03471
2022-10-02 23:09:09.519 DEBUG 1 --- [onnection adder] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - After adding stats (total=10, active=0, idle=10, waiting=0)
2022-10-02 23:09:09.826 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-10-02 23:09:09.832 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-10-02 23:09:10.419 WARN 1 --- [ main] 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-10-02 23:09:11.224 INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-10-02 23:09:11.314 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-10-02 23:09:11.325 INFO 1 --- [ main] io.pomatti.app.books.BookApplication : Started BookApplication in 11.913 seconds (JVM running for 12.911)
2022-10-02 23:09:11.412 INFO 1 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-10-02 23:09:11.415 INFO 1 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-10-02 23:09:11.415 DEBUG 1 --- [ionShutdownHook] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Before shutdown stats (total=10, active=0, idle=10, waiting=0)
2022-10-02 23:09:11.416 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:1 ClientConnectionId: 1061c2f8-febf-4f1f-b9f6-86ee6dd22af4: (connection evicted)
2022-10-02 23:09:11.416 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:2 ClientConnectionId: 5035df48-1a77-406f-95b1-99d289e2d70e: (connection evicted)
2022-10-02 23:09:11.417 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:3 ClientConnectionId: 2f01f8bb-e542-4351-9b5c-dcf7cd6084ef: (connection evicted)
2022-10-02 23:09:11.417 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:4 ClientConnectionId: fd8950e7-85e8-4ae2-80be-8d88d3a7c84d: (connection evicted)
2022-10-02 23:09:11.418 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:5 ClientConnectionId: 73205252-2e69-4a7d-b347-9ba7d8e6458f: (connection evicted)
2022-10-02 23:09:11.418 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:6 ClientConnectionId: 0814ccbd-f55c-4442-925d-be9046619eb5: (connection evicted)
2022-10-02 23:09:11.419 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:7 ClientConnectionId: f5fb5f48-1c99-4b0c-9b58-828627cfaac2: (connection evicted)
2022-10-02 23:09:11.419 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:8 ClientConnectionId: 730e1bf3-1e7b-4416-980e-9a64cda711ea: (connection evicted)
2022-10-02 23:09:11.420 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:9 ClientConnectionId: 23786119-d561-4da6-a59e-08ceb76c7065: (connection evicted)
2022-10-02 23:09:11.420 DEBUG 1 --- [nnection closer] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Closing connection ConnectionID:10 ClientConnectionId: 9cc6c870-b6a2-4ee3-bc06-14d81bd03471: (connection evicted)
2022-10-02 23:09:11.421 DEBUG 1 --- [ionShutdownHook] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - After shutdown stats (total=0, active=0, idle=0, waiting=0)
2022-10-02 23:09:11.421 INFO 1 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
My 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.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>io.pomatti.app</groupId>
<artifactId>order</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>order</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>11.2.1.jre17</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Main class:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#SpringBootApplication
#RestController
#RequestMapping("/api/books")
public class BookApplication {
public static void main(String[] args) {
SpringApplication.run(BookApplication.class, args);
}
#Autowired
BookRepository repository;
#PostMapping("/")
public Book post(#RequestBody Book order) {
var book = new Book();
book.setName("Eternal Sunshine");
book.setAuthor("Anonymous");
return repository.save(book);
}
}
Dockerfile:
# syntax=docker/dockerfile:1
FROM eclipse-temurin:17-jdk-jammy as builder
WORKDIR /opt/app
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN ./mvnw dependency:go-offline
COPY ./src ./src
RUN ./mvnw clean install
FROM eclipse-temurin:17-jre-jammy
WORKDIR /opt/app
EXPOSE 8080
COPY --from=builder /opt/app/target/*.jar /opt/app/*.jar
ENTRYPOINT ["java", "-jar", "/opt/app/*.jar" ]
Pods were being restarted due to a too short initial delay for the health probe, which I had set for 3s. I've increased it to 10s and it solved the issue.
probes = [
{
type = "Liveness"
httpGet = {
path = "/actuator/health"
port = var.ingress_target_port
httpHeaders = [
{
name = "Custom-Header"
value = "Awesome"
}
]
}
initialDelaySeconds = 10
periodSeconds = 5
}
]
I've found that out by looking into the System Logs available for each container.

My h2 working, but i cant connect inside of h2-console

Yoo coder, have one issue with h2-console.When i created some entitys on start,my h2 worked and i could open my h2-console and saw there tables ,but after some time i want connect again and doesn't work now.Meanwhile i added some lines and classes,but idk why doesn't work my h2-console,cause i don't touch application properties.
After lick on conect or testconect i got this error
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Mar 14 19:12:33 CET 2022
There was an unexpected error (type=Forbidden, status=403).
My github project: https://github.com/Wynnyy/bookingdoctor-project.git
logs
2022-03-14 19:12:16.222 INFO 23108 --- [ main] s.w.b.BookingdoctorApplication : Starting BookingdoctorApplication using Java 17.0.2 on DESKTOP-K3O8I67 with PID 23108 (C:\Users\Patrik Severín\IdeaProjects\bookingdoctor\target\classes started by Wynny in C:\Users\Patrik Severín\IdeaProjects\bookingdoctor)
2022-03-14 19:12:16.224 INFO 23108 --- [ main] s.w.b.BookingdoctorApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-14 19:12:16.928 INFO 23108 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-14 19:12:16.986 INFO 23108 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47 ms. Found 2 JPA repository interfaces.
2022-03-14 19:12:17.670 INFO 23108 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-03-14 19:12:17.682 INFO 23108 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-03-14 19:12:17.682 INFO 23108 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-14 19:12:17.780 INFO 23108 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-03-14 19:12:17.780 INFO 23108 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1503 ms
2022-03-14 19:12:17.829 INFO 23108 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-14 19:12:18.068 INFO 23108 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-03-14 19:12:18.080 INFO 23108 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:wynny'
2022-03-14 19:12:18.277 INFO 23108 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-03-14 19:12:18.331 INFO 23108 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.5.Final
2022-03-14 19:12:18.497 INFO 23108 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-03-14 19:12:18.627 INFO 23108 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-03-14 19:12:19.225 INFO 23108 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-03-14 19:12:19.232 INFO 23108 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-03-14 19:12:19.540 WARN 23108 --- [ main] 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-03-14 19:12:19.708 INFO 23108 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will not secure any request
2022-03-14 19:12:20.112 INFO 23108 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-14 19:12:20.211 INFO 23108 --- [ main] s.w.b.BookingdoctorApplication : Started BookingdoctorApplication in 4.362 seconds (JVM running for 4.745)
2022-03-14 19:12:24.415 INFO 23108 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-14 19:12:24.415 INFO 23108 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-14 19:12:24.417 INFO 23108 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
By default, spring-security will protect each and every end-point - So, for /error you need to manually configure like the following -
#EnableWebSecurity
public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
#Override
public void configure(HttpSecurity auth) {
auth.csrf().disable()
.authorizeRequests()
.antMatchers("/error/**").permitAll() // permit-all for /error page
.anyRequest().authenticated();
}
}
For future reference:
In Spring Boot 3.0 / Spring Security 6.0 http.antMatcher() is not longer available and was replaced with http.securityMatcher().
So Subham's answer would look like that:
#Configuration
public class SecurityConfiguration {
#Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((authz) -> authz.anyRequest().permitAll())
.csrf().disable()
.securityMatcher("/error/**")
.httpBasic(withDefaults());
return http.build();
}
}

Intellij Community Edition showing this error on schema.sql file as can see on image that I droped here

When I run the application this shutdown and don't allow me enter on H2 database on localhost h2 URL.
Is anyone else having this same problem?
:: Spring Boot :: (v2.4.1)
2020-12-22 15:23:08.377 INFO 4937 --- [ restartedMain] c.l.suraapp.SuraAppApplication : Starting SuraAppApplication using Java 15 on goemon with PID 4937 (/home/leporoni/Documents/JavaProjects/SuraApp/target/classes started by leporoni in /home/leporoni/Documents/JavaProjects/SuraApp)
2020-12-22 15:23:08.381 INFO 4937 --- [ restartedMain] c.l.suraapp.SuraAppApplication : No active profile set, falling back to default profiles: default
2020-12-22 15:23:08.554 INFO 4937 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-12-22 15:23:10.115 INFO 4937 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-12-22 15:23:10.228 INFO 4937 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 84 ms. Found 1 JPA repository interfaces.
2020-12-22 15:23:11.011 INFO 4937 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-12-22 15:23:11.580 INFO 4937 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-12-22 15:23:11.836 INFO 4937 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-12-22 15:23:11.972 INFO 4937 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.25.Final
2020-12-22 15:23:12.653 INFO 4937 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2020-12-22 15:23:12.967 INFO 4937 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-12-22 15:23:13.927 INFO 4937 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-12-22 15:23:13.941 INFO 4937 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-12-22 15:23:13.959 INFO 4937 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-12-22 15:23:14.520 INFO 4937 --- [ restartedMain] c.l.suraapp.SuraAppApplication : Started SuraAppApplication in 7.451 seconds (JVM running for 9.275)
2020-12-22 15:23:14.529 INFO 4937 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-12-22 15:23:14.564 INFO 4937 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-12-22 15:23:14.581 INFO 4937 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 0

Cant reach Endpoint in Controller, despite it beeing intialised

I read this
and this
The main ideas are that somebody has the wrong structure and components are not beeing scanned, I have a correct one.
My controller is beeing initialised normaly. I tested it debugging and seting the breakpoint on the contructor. It is beiing runned. DEspite of the that the endpoint could not be reached by my tests nor by postman, nor in the browser. I am getting a 404.
I am using gradle. structured my code like this. Already spent 3 Hours trying to fix this, but without success.
My controller looks like this.
package com.fressnapf.microservices.orderhistory.controller.impl;
#RestController
#RequestMapping("/customer")
public class OrderHistoryController implements IOrderHistoryController {
...
#Override
#ResponseStatus(value = HttpStatus.OK)
#RequestMapping(value = "/{customerid}/orders}", method = RequestMethod.GET, produces = "application/json")
public String getOrders(#PathVariable("customerid") String customerid, #RequestParam(required = false) String timeFrom,
#RequestParam(required = false) String timeTo, #RequestParam(required = false) String openOnly) {
...
}
}
Aplplication class
package com.fressnapf.microservices.orderhistory;
#SpringBootApplication()
#ImportResource({"classpath*:applicationContext.xml"})
#Configuration()
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
this is the response I am getting
{
"timestamp": "2020-03-03T16:00:33.489+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/customer/000000000/orders"
}
this is the log I am getting in the app
2020-03-03 16:59:27.595 INFO 10406 --- [ main] c.f.m.orderhistory.Application : Starting Application on debian-sgtechedge with PID 10406 (/home/sergeygerodes/projects/scporderhistoryservice/build/classes/java/main started by sgerodes in /home/sergeygerodes/projects/scporderhistoryservice)
2020-03-03 16:59:27.602 INFO 10406 --- [ main] c.f.m.orderhistory.Application : No active profile set, falling back to default profiles: default
2020-03-03 16:59:28.414 INFO 10406 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-03 16:59:28.441 INFO 10406 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 0 JPA repository interfaces.
2020-03-03 16:59:28.768 INFO 10406 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-03-03 16:59:29.035 INFO 10406 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-03 16:59:29.046 INFO 10406 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-03 16:59:29.047 INFO 10406 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-03-03 16:59:29.140 INFO 10406 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-03 16:59:29.140 INFO 10406 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1475 ms
2020-03-03 16:59:29.294 INFO 10406 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-03 16:59:29.405 INFO 10406 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-03-03 16:59:29.424 INFO 10406 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:orderhistory'
2020-03-03 16:59:29.517 INFO 10406 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-03-03 16:59:29.565 INFO 10406 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}
2020-03-03 16:59:29.660 INFO 10406 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-03 16:59:29.741 INFO 10406 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-03-03 16:59:29.886 INFO 10406 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-03-03 16:59:29.892 INFO 10406 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-03 17:00:28.614 WARN 10406 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=59s108ms538?s586ns).
2020-03-03 17:00:28.685 WARN 10406 --- [ main] 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
2020-03-03 17:00:28.845 INFO 10406 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-03 17:00:29.052 INFO 10406 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-03 17:00:29.060 INFO 10406 --- [ main] c.f.m.orderhistory.Application : Started Application in 61.937 seconds (JVM running for 62.493)
2020-03-03 17:00:33.395 INFO 10406 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-03 17:00:33.395 INFO 10406 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-03-03 17:00:33.404 INFO 10406 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 9 ms
the whole applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="loggerService"
class="com.fressnapf.sdk.logger.service.impl.DefaultLogService" />
<bean id="dataService"
class="com.fressnapf.sdk.dataaccess.services.impl.H2DataProvider">
<constructor-arg index="0" value="${spring.datasource.url}"/>
<constructor-arg index="1" value="${spring.datasource.username}"/>
<constructor-arg index="2" value="${spring.datasource.password}"/>
</bean>
</beans>
If you copied your controller code and pasted it here...
There is a close bracket too much. I tested it on one of my controllers and it shows the same behaviour.
#RequestMapping(value = "/{customerid}/orders-->}<--"...

Query language problem with JPA +Hibernate+Mysql

I have developed a java stand alone application (java+hibernate) , now I am replanting which to java 8+springboot+jpa+hibernate+mysql framework. I used HQL in my old project, but there seems to be some problems with SQL sentences in the new framework , for example, I have to change "From p where id=(:parameter)" to "Select * from p where id=:parameter" by removing the bracket.
BEAN
#Entity
public class Place extends Groupunit_Defined implements Interface_Entity
{
......
#ManyToOne(targetEntity=Place_Definer.class)
#JoinColumn(name="Groupunit_Definer",nullable=false)
private Place_Definer Groupunit_Definer;//
.....
}
#Entity
public class Place_Definer extends Groupunit_Definer
{
......
#Column(nullable=false,length=150)
private String Classification;
…….
}
#SuppressWarnings("unchecked")
public ArrayList Simply_get_thing_list
(
String Query_String,
ArrayList Parameter_List,
Class Thing_Class
)
{
Query q=Entity_Manager.createNativeQuery(Query_String,Thing_Class);
…….
return Thing_List;
}
SQL SENTENCE
"SELECT * FROM Place p WHERE p.Groupunit_Definer.Classification='Jurisdiction'"
HIBERNATE CONFIG
spring.jpa.database = MYSQL
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
ERROR MESSAGE
:: Spring Boot :: (v1.5.21.RELEASE)
2019-09-04 05:28:11.851 INFO 2508 --- [ main] c.s.mirrorworld.mirrorworldApplication : Starting mirrorworldApplication on LAPTOP-FAS0SHLM with PID 2508 (C:\Users\yueho\eclipse-workspace\mirrorworld\target\classes started by yueho in C:\Users\yueho\eclipse-workspace\mirrorworld)
2019-09-04 05:28:11.859 INFO 2508 --- [ main] c.s.mirrorworld.mirrorworldApplication : No active profile set, falling back to default profiles: default
2019-09-04 05:28:12.066 INFO 2508 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#2f217633: startup date [Wed Sep 04 05:28:12 CST 2019]; root of context hierarchy
2019-09-04 05:28:15.937 INFO 2508 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-09-04 05:28:15.994 INFO 2508 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-09-04 05:28:16.257 INFO 2508 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2019-09-04 05:28:16.260 INFO 2508 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-09-04 05:28:16.263 INFO 2508 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2019-09-04 05:28:16.559 INFO 2508 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-09-04 05:28:17.740 INFO 2508 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-04 05:28:19.002 WARN 2508 --- [ main] o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : update . Supported values include create, create-drop, update, and validate. Ignoring
2019-09-04 05:28:20.031 INFO 2508 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-04 05:28:24.577 INFO 2508 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2019-09-04 05:28:24.607 INFO 2508 --- [ main] c.s.mirrorworld.mirrorworldApplication : Started mirrorworldApplication in 13.439 seconds (JVM running for 24.733)
2019-09-04 05:28:33.326 INFO 2508 --- [WT-EventQueue-0] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2019-09-04 05:28:33.844 WARN 2508 --- [WT-EventQueue-0] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1054, SQLState: 42S22
2019-09-04 05:28:33.845 ERROR 2508 --- [WT-EventQueue-0] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'p.Groupunit_Definer.Classification' in 'where clause'
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at ……
org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:375)
at ……
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at …...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'p.Groupunit_Definer.Classification' in 'where clause'
The problem has been solved by changing "createNativeQuery" to "createQuery", thank you to

Categories