validate field length while reading csv file in spring batch - spring

Is there any way to validate field length while reading csv file in spring-boot batch FlatFileItemReader?
I tried javax.validation and set min and max length in pojo, but don't know how to trigger the validation.

I have created an example here with READ.me here.
I override the FlatItemReader and then perform Bean Validation using Hibernate Validator at Reader level as below
public class SimpleReader extends FlatFileItemReader<SoccerTeam> {
private Validator factory = Validation.buildDefaultValidatorFactory().getValidator();
#Override
public SoccerTeam doRead() throws Exception {
SoccerTeam soccerTeam = super.doRead();
if (Objects.isNull(soccerTeam)) return null;
Set<ConstraintViolation<SoccerTeam>> violations = this.factory.validate(soccerTeam);
if (!violations.isEmpty()) {
System.out.println(violations);
String errorMsg = String.format("The input has validation failed. Data is '%s'", soccerTeam);
throw new FlatFileParseException(errorMsg, Objects.toString(soccerTeam));
}
else {
return soccerTeam;
}
}
}
The model is using validation annotation
package com.bigzidane.example.springbatch;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
public class SoccerTeam {
#Size(max = 60)
private String name;
private String national;
#Min(value = 1)
#Max(value = 100)
private int rank;
public void setName(String name) {
this.name = name;
}
public void setNational(String national) {
this.national = national;
}
public void setRank(int rank) {
this.rank = rank;
}
#Override
public String toString() {
return "SoccerTeam{" +
"name='" + name + '\'' +
", national='" + national + '\'' +
", rank='" + rank + '\'' +
'}';
}
}
For the full code, please take a look here
Example run locally
Input is
name,national,rank
real madrid,spain,100
ars,english,1
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.9.RELEASE)
2019-10-05 14:41:27.754 INFO 10912 --- [ main] c.b.example.springbatch.HelloBatch : Starting HelloBatch on WINDOWS-ESDA5FC with PID 10912 (C:\Users\dotha\IdeaProjects\spring-boot-batch\target\classes started by dotha in C:\Users\dotha\IdeaProjects\spring-boot-batch)
2019-10-05 14:41:27.760 INFO 10912 --- [ main] c.b.example.springbatch.HelloBatch : No active profile set, falling back to default profiles: default
2019-10-05 14:41:28.985 INFO 10912 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-10-05 14:41:29.232 INFO 10912 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-10-05 14:41:29.383 INFO 10912 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: H2
2019-10-05 14:41:29.684 INFO 10912 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2019-10-05 14:41:29.934 INFO 10912 --- [ main] c.b.example.springbatch.HelloBatch : Started HelloBatch in 2.643 seconds (JVM running for 3.269)
2019-10-05 14:41:29.936 INFO 10912 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2019-10-05 14:41:30.035 INFO 10912 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=processJob]] launched with the following parameters: [{run.id=1}]
2019-10-05 14:41:30.066 INFO 10912 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
SoccerTeam{name='real madrid', national='spain', rank='100'}
SoccerTeam{name='ars', national='english', rank='1'}
2019-10-05 14:41:30.220 INFO 10912 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=processJob]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED]
2019-10-05 14:41:30.225 INFO 10912 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-10-05 14:41:30.227 INFO 10912 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Now if the input has validation failed
Input is
name,national,rank
real madrid,spain,101
ars,english,1
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.9.RELEASE)
2019-10-05 14:42:37.757 INFO 11268 --- [ main] c.b.example.springbatch.HelloBatch : Starting HelloBatch on WINDOWS-ESDA5FC with PID 11268 (C:\Users\dotha\IdeaProjects\spring-boot-batch\target\classes started by dotha in C:\Users\dotha\IdeaProjects\spring-boot-batch)
2019-10-05 14:42:37.761 INFO 11268 --- [ main] c.b.example.springbatch.HelloBatch : No active profile set, falling back to default profiles: default
2019-10-05 14:42:39.319 INFO 11268 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-10-05 14:42:39.648 INFO 11268 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-10-05 14:42:39.798 INFO 11268 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: H2
2019-10-05 14:42:40.101 INFO 11268 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2019-10-05 14:42:40.372 INFO 11268 --- [ main] c.b.example.springbatch.HelloBatch : Started HelloBatch in 3.231 seconds (JVM running for 3.89)
2019-10-05 14:42:40.374 INFO 11268 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2019-10-05 14:42:40.524 INFO 11268 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=processJob]] launched with the following parameters: [{run.id=1}]
2019-10-05 14:42:40.559 INFO 11268 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
[ConstraintViolationImpl{interpolatedMessage='must be less than or equal to 100', propertyPath=rank, rootBeanClass=class com.bigzidane.example.springbatch.SoccerTeam, messageTemplate='{javax.validation.constraints.Max.message}'}]
2019-10-05 14:42:40.746 ERROR 11268 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step step1 in job processJob
org.springframework.batch.item.file.FlatFileParseException: The input has validation failed. Data is 'SoccerTeam{name='real madrid', national='spain', rank='101'}'
at com.bigzidane.example.springbatch.SimpleReader.doRead(SimpleReader.java:25) ~[classes/:na]
at com.bigzidane.example.springbatch.SimpleReader.doRead(SimpleReader.java:12) ~[classes/:na]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:92) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:94) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:161) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:119) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:113) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:203) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) [spring-aop-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.1.10.RELEASE.jar:5.1.10.RELEASE]
at com.sun.proxy.$Proxy44.run(Unknown Source) [na:na]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:207) [spring-boot-autoconfigure-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:181) [spring-boot-autoconfigure-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:168) [spring-boot-autoconfigure-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:163) [spring-boot-autoconfigure-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:781) [spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:765) [spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319) [spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE]
at com.bigzidane.example.springbatch.HelloBatch.main(HelloBatch.java:9) [classes/:na]
2019-10-05 14:42:40.759 INFO 11268 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=processJob]] completed with the following parameters: [{run.id=1}] and the following status: [FAILED]
2019-10-05 14:42:40.764 INFO 11268 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-10-05 14:42:40.768 INFO 11268 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 0

If you want to perform the validation at the reader level, you can use a ItemReadListener or by overriding FlatFileItemReader and calling the validation logic in doRead as shown by #Nghia Do.
Item validation is a typical use case for an item processor. If you use Spring Batch 4.1+, you can use the BeanValidatingItemProcessor in your chunk-oriented step. You can find an example here: https://docs.spring.io/spring-batch/4.1.x/reference/html/whatsnew.html#whatsNewBeanValidationApi

Related

Spring Batch 5.0 with Spring Boot -- Tasklet job not starting automatically

I have a very simple Spring Boot project with Spring Batch 5.0 and a CommmandLineRunner. There is one Job, one step, and one tasklet that simply prints "Running".
I followed directions and would expect the job to start and complete.
No errors; the Batch database table are being created; the Job and Step beans are being created.
It just doesn't run.
I would be grateful for any insights or assistance!
NOTE: If I launch the job explicitly from the CommandLineRunner using an autowired JobLauncher, it works fine. It just doesn't launch the job automatically (as promised).
NOTE 2: Removing #EnableBatchProcessing makes no difference.
Code follows
application.properties:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/postgres
spring.batch.jdbc.initialize-schema=always
spring.batch.job.enabled=true
Application.java:
#SpringBootApplication
#EnableBatchProcessing
public class Application implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Override
public void run(String... args) throws Exception {
System.out.println("Starting...");
Thread.sleep(2000);
}
}
Job configuration:
#Configuration
public class AbacusJobConfiguration {
Logger logger = LoggerFactory.getLogger(AbacusJobConfiguration.class);
#Bean
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager, Tasklet tasklet1) {
logger.info("Building step");
return new StepBuilder("myTasklet", jobRepository)
.tasklet(tasklet1, transactionManager).allowStartIfComplete(true)
.build();
}
#Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager, Step step1) {
return new JobBuilder("myJob", jobRepository)
.incrementer(new RunIdIncrementer())
.start(step1)
.build();
}
#Bean
public MyTasklet myTasklet() {
logger.info("Building tasklet");
var tasklet = new MyTasklet();
return tasklet;
}
}
Tasklet:
public class MyTasklet implements Tasklet {
#Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
System.out.println("Running MyTasklet");
return RepeatStatus.FINISHED;
}
}
Runtime log:
2023-01-30T10:54:07.407-05:00 INFO 72774 --- [ main] c.optionmetrics.abacuscli.Application : Starting Application using Java 17.0.6 with PID 72774 (/Users/dhait/IdeaProjects/abacus-cli/target/classes started by dhait in /Users/dhait/IdeaProjects/abacus-cli)
2023-01-30T10:54:07.410-05:00 INFO 72774 --- [ main] c.optionmetrics.abacuscli.Application : No active profile set, falling back to 1 default profile: "default"
2023-01-30T10:54:07.626-05:00 INFO 72774 --- [ main] o.s.b.c.c.annotation.BatchRegistrar : Finished Spring Batch infrastructure beans configuration in 2 ms.
2023-01-30T10:54:07.836-05:00 INFO 72774 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-01-30T10:54:07.918-05:00 INFO 72774 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection#6ae7deac
2023-01-30T10:54:07.919-05:00 INFO 72774 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-01-30T10:54:07.928-05:00 INFO 72774 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: POSTGRES
2023-01-30T10:54:07.940-05:00 INFO 72774 --- [ main] c.o.abacuscli.AbacusJobConfiguration : Building tasklet
2023-01-30T10:54:07.942-05:00 INFO 72774 --- [ main] c.o.abacuscli.AbacusJobConfiguration : Building step
2023-01-30T10:54:07.954-05:00 INFO 72774 --- [ main] .c.a.BatchObservabilityBeanPostProcessor : No Micrometer observation registry found, defaulting to ObservationRegistry.NOOP
2023-01-30T10:54:07.959-05:00 INFO 72774 --- [ main] .c.a.BatchObservabilityBeanPostProcessor : No Micrometer observation registry found, defaulting to ObservationRegistry.NOOP
2023-01-30T10:54:07.963-05:00 INFO 72774 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2023-01-30T10:54:08.040-05:00 INFO 72774 --- [ main] c.optionmetrics.abacuscli.Application : Started Application in 0.882 seconds (process running for 1.246)
Starting...
2023-01-30T10:54:10.050-05:00 INFO 72774 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2023-01-30T10:54:10.054-05:00 INFO 72774 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
With Spring Boot 3, there is no need for #EnableBatchProcessing. If you add it, the auto-configuration of Spring Batch (including the automatic launching of jobs at startup) will back off.
This is mentioned in the migration guide of Spring Boot 3.
EDIT: Not able to reproduce the issue. Things are working as expected with Spring Batch 5 and Spring Boot 3.
$>curl https://start.spring.io/starter.zip -d dependencies=h2,batch -d type=maven-project -o my-batch-job.zip
$>unzip my-batch-job.zip
$> # Paste AbacusJobConfiguration and MyTasklet code in the demo package + add imports
$>./mvnw package
$>./mvnw spring-boot:run
This prints:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.2)
2023-01-31T07:48:24.206+01:00 INFO 91983 --- [ main] com.example.demo.DemoApplicationTests : Starting DemoApplicationTests using Java 17.0.4 with PID 91983 (started by mbenhassine in /Users/mbenhassine/Downloads/so75287102)
2023-01-31T07:48:24.207+01:00 INFO 91983 --- [ main] com.example.demo.DemoApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-01-31T07:48:24.625+01:00 INFO 91983 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-01-31T07:48:24.779+01:00 INFO 91983 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:0b237f7c-fec8-446f-b2ac-086801ddb7fd user=SA
2023-01-31T07:48:24.780+01:00 INFO 91983 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-01-31T07:48:24.858+01:00 INFO 91983 --- [ main] c.example.demo.AbacusJobConfiguration : Building tasklet
2023-01-31T07:48:24.860+01:00 INFO 91983 --- [ main] c.example.demo.AbacusJobConfiguration : Building step
2023-01-31T07:48:24.957+01:00 INFO 91983 --- [ main] com.example.demo.DemoApplicationTests : Started DemoApplicationTests in 0.91 seconds (process running for 1.585)
2023-01-31T07:48:24.958+01:00 INFO 91983 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: []
2023-01-31T07:48:24.990+01:00 INFO 91983 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=myJob]] launched with the following parameters: [{'run.id':'{value=1, type=class java.lang.Long, identifying=true}'}]
2023-01-31T07:48:25.009+01:00 INFO 91983 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [myTasklet]
Running MyTasklet
2023-01-31T07:48:25.017+01:00 INFO 91983 --- [ main] o.s.batch.core.step.AbstractStep : Step: [myTasklet] executed in 8ms
2023-01-31T07:48:25.025+01:00 INFO 91983 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=myJob]] completed with the following parameters: [{'run.id':'{value=1, type=class java.lang.Long, identifying=true}'}] and the following status: [COMPLETED] in 23ms
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.556 s - in com.example.demo.DemoApplicationTests
2023-01-31T07:48:25.312+01:00 INFO 91983 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2023-01-31T07:48:25.315+01:00 INFO 91983 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.

Running Spring Boot Native Application on Azure Functions: Permission denied with server.port: 80

I have created a simple Spring Boot Application and compiled it with Spring Native gradle bootBuildImage. I uploaded the docker container to an private registry and deployed it to Microsoft Azure Function. Accessing the function will correctly start the Spring Boot Application inside the docker container. But it crashes with following exception:
2021-11-09T15:46:55.996267267Z 2021-11-09 15:46:55.996 INFO 1 --- [ main] o.s.nativex.NativeListener : This application is bootstrapped with code generated with Spring AOT
2021-11-09T15:46:55.997230973Z
2021-11-09T15:46:55.997396574Z . ____ _ __ _ _
2021-11-09T15:46:55.997539875Z /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
2021-11-09T15:46:55.997679976Z ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2021-11-09T15:46:55.997816777Z \\/ ___)| |_)| | | | | || (_| | ) ) ) )
2021-11-09T15:46:55.997979078Z ' |____| .__|_| |_|_| |_\__, | / / / /
2021-11-09T15:46:55.998114779Z =========|_|==============|___/=/_/_/_/
2021-11-09T15:46:55.999546489Z :: Spring Boot :: (v2.5.6)
2021-11-09T15:46:55.999559889Z
2021-11-09T15:46:56.065075944Z 2021-11-09 15:46:56.054 INFO 1 --- [ main] o.s.boot.SpringApplication : Starting application using Java 11.0.13 on 421026966d15 with PID 1 (started by cnb in /workspace)
2021-11-09T15:46:56.065102544Z 2021-11-09 15:46:56.056 INFO 1 --- [ main] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2021-11-09T15:46:56.095177553Z 2021-11-09 15:46:56.094 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-11-09T15:46:56.097067866Z 2021-11-09 15:46:56.096 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1 ms. Found 1 JPA repository interfaces.
2021-11-09T15:46:56.147529016Z 2021-11-09 15:46:56.147 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 80 (http)
2021-11-09T15:46:56.148811625Z 2021-11-09 15:46:56.148 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-11-09T15:46:56.149445829Z 2021-11-09 15:46:56.148 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.54]
2021-11-09T15:46:56.154613565Z 2021-11-09 15:46:56.154 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-11-09T15:46:56.155352670Z 2021-11-09 15:46:56.154 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 95 ms
2021-11-09T15:46:56.177839326Z 2021-11-09 15:46:56.177 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-11-09T15:46:56.179695539Z 2021-11-09 15:46:56.179 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-11-09T15:46:56.181115849Z 2021-11-09 15:46:56.180 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-11-09T15:46:56.183164263Z 2021-11-09 15:46:56.182 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-11-09T15:46:56.533544294Z 2021-11-09 15:46:56.533 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-11-09T15:46:56.534665902Z 2021-11-09 15:46:56.533 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2021-11-09T15:46:56.675326478Z 2021-11-09 15:46:56.675 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-11-09T15:46:56.676515986Z 2021-11-09 15:46:56.676 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-11-09T15:46:56.722262803Z 2021-11-09 15:46:56.722 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
2021-11-09T15:46:56.746931074Z 2021-11-09 15:46:56.746 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-11-09T15:46:56.749313091Z 2021-11-09 15:46:56.749 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-11-09T15:46:56.750124797Z 2021-11-09 15:46:56.749 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2021-11-09T15:46:56.877499580Z 2021-11-09 15:46:56.877 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2021-11-09T15:46:56.878593388Z 2021-11-09 15:46:56.877 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-11-09T15:46:56.888123954Z 2021-11-09 15:46:56.880 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
2021-11-09T15:46:56.888151454Z
2021-11-09T15:46:56.888156354Z Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-11-09T15:46:56.888160554Z 2021-11-09 15:46:56.880 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
2021-11-09T15:46:56.888164954Z
2021-11-09T15:46:56.888168654Z org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-11-09T15:46:56.888172954Z at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[de.aditu.buchschrank.BuchschrankApplicationKt:5.3.12]
2021-11-09T15:46:56.888177354Z at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[de.aditu.buchschrank.BuchschrankApplicationKt:5.3.12]
2021-11-09T15:46:56.888181254Z at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[na:na]
2021-11-09T15:46:56.888196454Z at java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
2021-11-09T15:46:56.888200454Z at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[de.aditu.buchschrank.BuchschrankApplicationKt:5.3.12]
2021-11-09T15:46:56.888204354Z at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[de.aditu.buchschrank.BuchschrankApplicationKt:5.3.12]
2021-11-09T15:46:56.888208354Z at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[na:na]
2021-11-09T15:46:56.888212155Z at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[na:na]
2021-11-09T15:46:56.888216155Z at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
2021-11-09T15:46:56.888220055Z at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[de.aditu.buchschrank.BuchschrankApplicationKt:2.5.6]
2021-11-09T15:46:56.888224455Z at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[de.aditu.buchschrank.BuchschrankApplicationKt:2.5.6]
2021-11-09T15:46:56.888228555Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[de.aditu.buchschrank.BuchschrankApplicationKt:2.5.6]
2021-11-09T15:46:56.888232355Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[de.aditu.buchschrank.BuchschrankApplicationKt:2.5.6]
2021-11-09T15:46:56.888236255Z at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[de.aditu.buchschrank.BuchschrankApplicationKt:2.5.6]
2021-11-09T15:46:56.888240055Z at de.aditu.buchschrank.BuchschrankApplicationKt.main(BuchschrankApplication.kt:17) ~[na:na]
2021-11-09T15:46:56.888243955Z Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-11-09T15:46:56.888247755Z at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[na:na]
2021-11-09T15:46:56.888251555Z at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[na:na]
2021-11-09T15:46:56.888255455Z at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[de.aditu.buchschrank.BuchschrankApplicationKt:5.3.12]
2021-11-09T15:46:56.888259455Z ... 14 common frames omitted
2021-11-09T15:46:56.888263155Z Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
2021-11-09T15:46:56.888266855Z at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) ~[na:na]
2021-11-09T15:46:56.888270755Z at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[na:na]
2021-11-09T15:46:56.888275055Z at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[na:na]
2021-11-09T15:46:56.888281755Z ... 16 common frames omitted
2021-11-09T15:46:56.888285555Z Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
2021-11-09T15:46:56.888289355Z at org.apache.catalina.connector.Connector.startInternal(Connector.java:1075) ~[na:na]
2021-11-09T15:46:56.888293055Z at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[na:na]
2021-11-09T15:46:56.888296855Z at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) ~[na:na]
2021-11-09T15:46:56.888300655Z ... 18 common frames omitted
2021-11-09T15:46:56.888304255Z Caused by: java.net.SocketException: Permission denied
2021-11-09T15:46:56.888308255Z at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST_SocketException_constructor_df417f52c09624a386e25e5af85993f853394076(JNIJavaCallWrappers.java:0) ~[na:na]
2021-11-09T15:46:56.888312255Z at sun.nio.ch.Net.bind0(Net.java) ~[na:na]
2021-11-09T15:46:56.888315955Z at sun.nio.ch.Net.bind(Net.java:455) ~[na:na]
2021-11-09T15:46:56.888319655Z at sun.nio.ch.Net.bind(Net.java:447) ~[na:na]
2021-11-09T15:46:56.888323255Z at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) ~[na:na]
2021-11-09T15:46:56.888327055Z at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:271) ~[de.aditu.buchschrank.BuchschrankApplicationKt:9.0.54]
2021-11-09T15:46:56.888330955Z at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:226) ~[de.aditu.buchschrank.BuchschrankApplicationKt:9.0.54]
2021-11-09T15:46:56.888334755Z at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1208) ~[de.aditu.buchschrank.BuchschrankApplicationKt:9.0.54]
2021-11-09T15:46:56.888338655Z at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1294) ~[de.aditu.buchschrank.BuchschrankApplicationKt:9.0.54]
2021-11-09T15:46:56.888342555Z at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614) ~[de.aditu.buchschrank.BuchschrankApplicationKt:9.0.54]
2021-11-09T15:46:56.888346355Z at org.apache.catalina.connector.Connector.startInternal(Connector.java:1072) ~[na:na]
2021-11-09T15:46:56.888350255Z ... 20 common frames omitted
2021-11-09T15:46:56.888353856Z
Regarding the logs, Azure starts docker with
docker run -d -p 7502:80...
The first port seems to be random.
The full source code can be found here: https://github.com/lesestunden/buchschrank-backend
Does anybody have an idea whats going wrong?
Thanks a lot!
Your application should listen on a non-privileged port (> 1024).
The created container is unable to use a privileged port. The bootBuildImage task creates and runs images utilizing buildpacks (for runtime paketobuildpacks/run:tiny-cnb), the application in the container doesn't run as root. Therefore you can not listen on a port below 1024.
Spring boot uses paketo-buildpacks, which have some security-hardenings in them
The stack images are run as a dedicated non-root user when building
and running applications.
see paketo documentation
Solution is using a port bigger than 1024 (e.g. 8080) and configure the port like in this answer: Azure Functions with docker: How change port?

status:401 unauthorized in postman

Iam working in springboot application and iam trying to save the data in database, code is executing properly and not getting any error during execution but when iam trying to post the url in postman iam getting status: 401 unauthorized
any quick suggestion
console
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2020-12-08 17:34:07.094 INFO 7236 --- [ main] c.regestration.RegestrationApplication : Starting RegestrationApplication on Darshan with PID 7236 (C:\Users\admin\Desktop\regestration\target\classes started by admin in C:\Users\admin\Desktop\regestration)
2020-12-08 17:34:07.111 INFO 7236 --- [ main] c.regestration.RegestrationApplication : No active profile set, falling back to default profiles: default
2020-12-08 17:34:08.584 INFO 7236 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-12-08 17:34:08.803 INFO 7236 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 202ms. Found 1 JPA repository interfaces.
2020-12-08 17:34:10.751 INFO 7236 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8085 (http)
2020-12-08 17:34:10.788 INFO 7236 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-08 17:34:10.788 INFO 7236 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-12-08 17:34:11.158 INFO 7236 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-12-08 17:34:11.158 INFO 7236 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3827 ms
2020-12-08 17:34:11.617 INFO 7236 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-12-08 17:34:11.815 INFO 7236 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-12-08 17:34:11.935 WARN 7236 --- [ 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-12-08 17:34:12.006 INFO 7236 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2020-12-08 17:34:13.075 INFO 7236 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-12-08 17:34:13.554 INFO 7236 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-12-08 17:34:14.050 INFO 7236 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 7406d0eb-72dc-4ce4-a8cc-220d3c523098
2020-12-08 17:34:14.273 INFO 7236 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#574cd322, org.springframework.security.web.context.SecurityContextPersistenceFilter#55e2fe3c, org.springframework.security.web.header.HeaderWriterFilter#64f1fd08, org.springframework.security.web.csrf.CsrfFilter#7187bac9, org.springframework.security.web.authentication.logout.LogoutFilter#5c8e67b9, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#1174a305, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#43e1692f, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#45c2e0a6, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#1f3165e7, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#12c60152, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#692e028d, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#119c745c, org.springframework.security.web.session.SessionManagementFilter#282ffbf5, org.springframework.security.web.access.ExceptionTranslationFilter#6c15e8c7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#3a08078c]
2020-12-08 17:34:14.874 INFO 7236 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8085 (http) with context path ''
2020-12-08 17:34:14.884 INFO 7236 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-12-08 17:34:14.889 INFO 7236 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-12-08 17:34:14.948 INFO 7236 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2020-12-08 17:34:18.480 INFO 7236 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-12-08 17:34:18.495 INFO 7236 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-12-08 17:34:18.881 INFO 7236 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-12-08 17:34:18.890 INFO 7236 --- [ main] c.regestration.RegestrationApplication : Started RegestrationApplication in 13.562 seconds (JVM running for 19.799)
2020-12-08 17:34:42.030 INFO 7236 --- [nio-8085-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-12-08 17:34:42.031 INFO 7236 --- [nio-8085-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-12-08 17:34:42.050 INFO 7236 --- [nio-8085-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 19 ms
controller
package com.regestration.controller;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.regestration.repository.Repository;
import com.regestration.user.User;
#RestController
public class Controller {
#Autowired
Repository repo;
#RequestMapping(value="/saveReg", method= RequestMethod.POST)
public HashMap<String, Object>saveRegestration(#RequestBody User user){
HashMap<String, Object> map = new HashMap<String, Object>();
repo.save(user);
map.put("code", "200");
map.put("code", "saved");
return map;
}
}
application.properties
spring.datasource.url= jdbc:mysql://localhost:3306/myshadi?useSSL=false
spring.datasource.username= root
spring.datasource.password= root
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto= update
server.port=8085
Spring is activating by default the security.
See line : Using generated security password: 7406d0eb-72dc-4ce4-a8cc-220d3c523098.
You have to inactivate the security if you don't need it : Spring boot Security Disable security

Flyway not finding migrations when run from IntelliJ when using Gradle

When I run my Spring Boot Kotlin application that uses Flyway from the command line, it seems to work, but from IntelliJ it fails. I created a minimal sample project that replicates the problem: https://github.com/pupeno/notflying
The error I get from IntelliJ is about the migrations not being found:
Caused by: java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.checkLocationExists(FlywayAutoConfiguration.java:184) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:149) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$ffc78d0a.CGLIB$flyway$0(<generated>) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$ffc78d0a$$FastClassBySpringCGLIB$$5b3da70f.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$ffc78d0a.flyway(<generated>) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 27 common frames omitted
The migrations are there and correctly named as far as I can see:
PS C:\Users\pupeno\Temporary\notflying> dir .\src\main\resources\db\migration\
Directory: C:\Users\pupeno\Temporary\notflying\src\main\resources\db\migration
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2019-08-26 08:32 718 V0001__create_countries_table.sql
PS C:\Users\pupeno\Temporary\notflying>
The IntelliJ configuration for running it looks like this:
I added:
logging.level.org.flywaydb=DEBUG
to application.properties and the full output of trying to start the application from IntelliJ looks like this:
"C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\jbr\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\lib\idea_rt.jar=50536:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\pupeno\Temporary\notflying\build\classes\java\main;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-data-jpa\2.1.7.RELEASE\5e4a5d5442f32f5e12b36674a620ec57b0b66c6e\spring-boot-starter-data-jpa-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-thymeleaf\2.1.7.RELEASE\cf9547e20aa6a32c0b0f53400db6eecfab660f86\spring-boot-starter-thymeleaf-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\2.1.7.RELEASE\fa43baf40bde3ecdb93ac9c545dd39f82ab29c35\spring-boot-starter-web-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-kotlin\2.9.9\446b0567b26965cf7db859ba48a73ab30b4016b7\jackson-module-kotlin-2.9.9.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-devtools\2.1.7.RELEASE\5a846c6e9ab67a4cbf7c4f22bc13bcab188198f9\spring-boot-devtools-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.flywaydb\flyway-core\5.2.4\50a92d39554615bd4ff56d148a359b20dc17f655\flyway-core-5.2.4.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.2.71\7512db3b3182753bd2e48ce8d345abbadc40fe6b\kotlin-reflect-1.2.71.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.2.71\5470d1f752cd342edb77e1062bac07e838d2cea4\kotlin-stdlib-jdk8-1.2.71.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-aop\2.1.7.RELEASE\4577d056af1f823bb7730c99f43c3268dd697310\spring-boot-starter-aop-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-jdbc\2.1.7.RELEASE\3ea97a134b44a886ff529215e7bec04bfd93fa5b\spring-boot-starter-jdbc-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\javax.transaction\javax.transaction-api\1.3\e006adf5cf3cca2181d16bd640ecb80148ec0fce\javax.transaction-api-1.3.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\javax.xml.bind\jaxb-api\2.3.1\8531ad5ac454cc2deb9d4d32c40c4d7451939b5d\jaxb-api-2.3.1.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.h2database\h2\1.4.199\7bf08152984ed8859740ae3f97fae6c72771ae45\h2-1.4.199.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.hibernate\hibernate-core\5.3.10.Final\e608b854325005edbf43cb2b6041fdafd3f2eb57\hibernate-core-5.3.10.Final.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-jpa\2.1.10.RELEASE\12639406aa28c3a5195a1a4c9077fe562f54bc31\spring-data-jpa-2.1.10.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aspects\5.1.9.RELEASE\a8aec853c345ed54a99627cee9f755ce7dbb734\spring-aspects-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\2.1.7.RELEASE\9c12f046a7c4ae110d89163a491ad0d7cf036e79\spring-boot-starter-json-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.1.7.RELEASE\e23f4e9460e0e2220b444e40fc7fd6e95f66e0fe\spring-boot-starter-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.thymeleaf\thymeleaf-spring5\3.0.11.RELEASE\de7bf0adf13b5e9c4811f95edf18279da193c0c6\thymeleaf-spring5-3.0.11.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.thymeleaf.extras\thymeleaf-extras-java8time\3.0.4.RELEASE\36e7175ddce36c486fff4578b5af7bb32f54f5df\thymeleaf-extras-java8time-3.0.4.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-tomcat\2.1.7.RELEASE\11f2a86aefefba72a4efe5ff18f4165a4b4e78b\spring-boot-starter-tomcat-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.hibernate.validator\hibernate-validator\6.0.17.Final\af73055fc4a103ab347c56e7da5a143d68a0170\hibernate-validator-6.0.17.Final.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\5.1.9.RELEASE\b9d4a2140488f0e6f9aa231e7938ae18da77b637\spring-webmvc-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.1.9.RELEASE\9fe4390420fdd0b63dc4ed90d9027dafa9f74f80\spring-web-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\2.9.9\4b04126963103216c9c43b0f34bbc36315654204\jackson-datatype-jdk8-2.9.9.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.9.9\a33df137557793b0404a486888dbe049f7abeeeb\jackson-datatype-jsr310-2.9.9.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-parameter-names\2.9.9\a92facb55a2538e7b2fe14294570a18b823ad431\jackson-module-parameter-names-2.9.9.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.9.9\d6eb9817d9c7289a91f043ac5ee02a6b3cc86238\jackson-databind-2.9.9.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.9.0\7c10d545325e3a6e72e06381afe469fd40eb701\jackson-annotations-2.9.0.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.2.71\4ce93f539e2133f172f1167291a911f83400a5d0\kotlin-stdlib-jdk7-1.2.71.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.2.71\d9717625bb3c731561251f8dd2c67a1011d6764c\kotlin-stdlib-1.2.71.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.1.7.RELEASE\2c9d3e2c6ea3cb435e99e2973009636b62a9d816\spring-boot-autoconfigure-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.1.7.RELEASE\1599a2ad1fc6d36dbfc2a7c0dd5dab3a0bb27c61\spring-boot-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.1.9.RELEASE\c37f8fe15a5ae4ea1f351bd46167fd492a84eefa\spring-context-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.1.9.RELEASE\bc2312ffad02251b9d472e4a7c0e472a58f50fbf\spring-aop-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.aspectj\aspectjweaver\1.9.4\9205229878f3d62fbd3a32a0fb6be2d6ad8589a9\aspectjweaver-1.9.4.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.zaxxer\HikariCP\3.2.0\6c66db1c636ee90beb4c65fe34abd8ba9396bca6\HikariCP-3.2.0.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-orm\5.1.9.RELEASE\220169d217f7114706141fc0afba425a5b368dce\spring-orm-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jdbc\5.1.9.RELEASE\3fd70356ba8d7c00c4081c1a207766352624414e\spring-jdbc-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\javax.activation\javax.activation-api\1.2.0\85262acf3ca9816f9537ca47d5adeabaead7cb16\javax.activation-api-1.2.0.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.hibernate.common\hibernate-commons-annotations\5.0.4.Final\965a18fdf939ee75e41f7918532d37b3a8350535\hibernate-commons-annotations-5.0.4.Final.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.3.2.Final\3789d00e859632e6c6206adc0c71625559e6e3b0\jboss-logging-3.3.2.Final.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\javax.persistence\javax.persistence-api\2.2\25665ac8c0b62f50e6488173233239120fc52c96\javax.persistence-api-2.2.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.javassist\javassist\3.23.2-GA\c5afe660a95e87ceb518e4f5cf02f5c56b547683\javassist-3.23.2-GA.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy\1.9.16\e7d63009be7b87ff1f15b72e5b8c59c897a8d8bd\byte-buddy-1.9.16.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\antlr\antlr\2.7.7\83cd2cd674a217ade95a4bb83a8a14f351f48bd0\antlr-2.7.7.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jboss\jandex\2.0.5.Final\7060f67764565b9ee9d467e3ed0cb8a9c601b23a\jandex-2.0.5.Final.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.4.0\291658ac2ce2476256c7115943652c0accb5c857\classmate-1.4.0.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.dom4j\dom4j\2.1.1\3dce5dbb3571aa820c677fadd8349bfa8f00c199\dom4j-2.1.1.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-commons\2.1.10.RELEASE\c73a76070181b59b19df6893e1ca729263a69b47\spring-data-commons-2.1.10.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-tx\5.1.9.RELEASE\a9125e2c8eeb193030f3972c6293616943c55ef2\spring-tx-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.1.9.RELEASE\5a03b3983108d73978aec2fa3e681aedad6782c\spring-beans-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.1.9.RELEASE\db3a2468c1b7d697ec3b3ec6e5652dc282994fe3\spring-expression-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.1.9.RELEASE\dc3815439579b4fa0c19970e6b8e5d774af8d988\spring-core-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.thymeleaf\thymeleaf\3.0.11.RELEASE\628ebb91f520053d4120b7b18bf78ff295d57461\thymeleaf-3.0.11.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\2.1.7.RELEASE\6e829f739992a7f368c0af44a08ed89ad2a1972f\spring-boot-starter-logging-2.1.7.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.11.2\6d37bf7b046c0ce2669f26b99365a2cfa45c4c18\log4j-to-slf4j-2.11.2.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.26\8031352b2bb0a49e67818bf04c027aa92e645d5c\jul-to-slf4j-1.7.26.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.26\77100a62c2e6f04b53977b9f541044d7d722693d\slf4j-api-1.7.26.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.3.2\934c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-websocket\9.0.22\45974d3443cc15ad9d10239d762d5e15759e6364\tomcat-embed-websocket-9.0.22.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\9.0.22\79f39903498b28adacb18fe2ea046edd306295a6\tomcat-embed-core-9.0.22.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\9.0.22\4da4b778b635a7e78ca7cd7288253e2e47b88a9f\tomcat-embed-el-9.0.22.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\javax.validation\validation-api\2.0.1.Final\cb855558e6271b1b32e716d24cb85c7f583ce09e\validation-api-2.0.1.Final.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.9.9\bfff5af9fb8347d26bbb7959cb9b4fe9a2b0ca5e\jackson-core-2.9.9.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.2.71\ba18ca1aa0e40eb6f1865b324af2f4cbb691c1ec\kotlin-stdlib-common-1.2.71.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.23\ec62d74fe50689c28c0ff5b35d3aebcaa8b5be68\snakeyaml-1.23.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.1.9.RELEASE\7c372790c999777d20f364960cf557dd74f890cf\spring-jcl-5.1.9.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.attoparser\attoparser\2.0.5.RELEASE\a93ad36df9560de3a5312c1d14f69d938099fa64\attoparser-2.0.5.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.unbescape\unbescape\1.1.6.RELEASE\7b90360afb2b860e09e8347112800d12c12b2a13\unbescape-1.1.6.RELEASE.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\pupeno\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.11.2\f5e9a2ffca496057d6891a3de65128efc636e26e\log4j-api-2.11.2.jar tech.flexpoint.notflying.NotflyingApplicationKt
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-08-26 10:36:00.478 INFO 7132 --- [ restartedMain] t.f.notflying.NotflyingApplicationKt : Starting NotflyingApplicationKt on Utopia-Planitia with PID 7132 (C:\Users\pupeno\Temporary\notflying\build\classes\java\main started by pupeno in C:\Users\pupeno\Temporary\notflying)
2019-08-26 10:36:00.484 INFO 7132 --- [ restartedMain] t.f.notflying.NotflyingApplicationKt : No active profile set, falling back to default profiles: default
2019-08-26 10:36:00.549 INFO 7132 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-08-26 10:36:00.550 INFO 7132 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-08-26 10:36:01.616 INFO 7132 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-26 10:36:01.641 INFO 7132 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16ms. Found 0 repository interfaces.
2019-08-26 10:36:02.113 INFO 7132 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e16cf649] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-26 10:36:02.433 INFO 7132 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-26 10:36:02.460 INFO 7132 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-26 10:36:02.460 INFO 7132 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.22]
2019-08-26 10:36:02.696 INFO 7132 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-26 10:36:02.696 INFO 7132 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2146 ms
2019-08-26 10:36:02.831 WARN 7132 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
2019-08-26 10:36:02.834 INFO 7132 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-08-26 10:36:02.848 INFO 7132 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-26 10:36:02.864 ERROR 7132 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[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]
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.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307) ~[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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[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.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at tech.flexpoint.notflying.NotflyingApplicationKt.main(NotflyingApplication.kt:13) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.7.RELEASE.jar:2.1.7.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 26 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.checkLocationExists(FlywayAutoConfiguration.java:184) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:149) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$616ac3e9.CGLIB$flyway$1(<generated>) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$616ac3e9$$FastClassBySpringCGLIB$$a2f39a48.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$616ac3e9.flyway(<generated>) ~[spring-boot-autoconfigure-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 27 common frames omitted
Process finished with exit code 0
I've tried this, with the same result, both with the JDK provided by IntelliJ (version 11 I think) as well as Oracle JDK 11:
PS C:\Users\pupeno\Temporary\notflying> java --version
java 12.0.2 2019-07-16
Java(TM) SE Runtime Environment (build 12.0.2+10)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
When I trigger a build in IntelliJ, I get some warning (not sure if relevant):
I re-created the project with Maven and it seems to work out of the box, with no issues. So, I'd say, the problem seems to be in how IntelliJ imports Gradle projects.
Perfectly work on my machine
Probably migrations not copied to build/resources/main/db directory
Try next:
Delete build directory
Invalidate idea cache link
Reimport gradle link
If that doesn't help replace Build to gradle build in configuration settings:
Also maybe gradle not have access to read migration file or parent directory. Check permissions in file system or try clone github repository to another folder.
Looks like Intellij might have created the directory as
src/main/resources/db.migration
with the files in a directory called db.migration, instead of
src/main/resources/db/migration
with the files in a directory called migration.
My try, which succeeded:
Rename to a name that isn't your name in mind.
Run gradle clean and start test.
Expect: No migrations found.
Rename it again to your desired name. Run the test again.
Expect: Migrations found!
Its definitely a bug in IntelliJ/Gradle where it doesn't detect resources to import when there is no builds exists before its compilation. Making changes to the script refreshes its state, and automatically imports the resource afterwards.
Working fine for me:
$ ./gradlew bootRun
./gradlew: 39: cd: can't cd to "./
> Task :bootRun
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-08-26 08:21:36.837 INFO 1789 --- [ restartedMain] t.f.notflying.NotflyingApplicationKt : Starting NotflyingApplicationKt on LAP025 with PID 1789 (/mnt/c/Users/bleug/Desktop/notflying/build/classes/kotlin/main started by bleug in /mnt/c/Users/bleug/Desktop/notflying)
2019-08-26 08:21:36.846 INFO 1789 --- [ restartedMain] t.f.notflying.NotflyingApplicationKt : No active profile set, falling back to default profiles: default
2019-08-26 08:21:37.116 INFO 1789 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-08-26 08:21:37.116 INFO 1789 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-08-26 08:21:40.958 INFO 1789 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-26 08:21:41.124 INFO 1789 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 106ms. Found 0 repository interfaces.
2019-08-26 08:21:42.578 INFO 1789 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$6414adf5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-26 08:21:43.698 INFO 1789 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-26 08:21:43.781 INFO 1789 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-26 08:21:43.782 INFO 1789 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.22]
2019-08-26 08:21:44.196 INFO 1789 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-26 08:21:44.196 INFO 1789 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 7080 ms
2019-08-26 08:21:44.735 INFO 1789 --- [ restartedMain] o.f.c.internal.license.VersionPrinter : Flyway Community Edition 5.2.4 by Boxfuse
2019-08-26 08:21:44.765 INFO 1789 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-08-26 08:21:45.433 INFO 1789 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-08-26 08:21:45.460 INFO 1789 --- [ restartedMain] o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
2019-08-26 08:21:45.607 WARN 1789 --- [ restartedMain] o.f.c.internal.database.base.Database : Flyway upgrade recommended: H2 1.4.199 is newer than this version of Flyway and support has not been tested.
2019-08-26 08:21:45.860 INFO 1789 --- [ restartedMain] o.f.core.internal.command.DbValidate : Successfully validated 1 migration (execution time 00:00.086s)
2019-08-26 08:21:45.893 INFO 1789 --- [ restartedMain] o.f.c.i.s.JdbcTableSchemaHistory : Creating Schema History table: "PUBLIC"."flyway_schema_history"
2019-08-26 08:21:45.976 INFO 1789 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Current version of schema "PUBLIC": << Empty Schema >>
2019-08-26 08:21:45.993 INFO 1789 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version 0001 - create countries table
2019-08-26 08:21:46.051 INFO 1789 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.165s)
2019-08-26 08:21:46.616 INFO 1789 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-08-26 08:21:46.939 INFO 1789 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-08-26 08:21:46.944 INFO 1789 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-08-26 08:21:47.555 INFO 1789 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-08-26 08:21:48.169 INFO 1789 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-08-26 08:21:48.963 INFO 1789 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-08-26 08:21:49.033 INFO 1789 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-08-26 08:21:49.920 INFO 1789 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-26 08:21:50.137 WARN 1789 --- [ restartedMain] 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-08-26 08:21:50.476 WARN 1789 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2019-08-26 08:21:51.143 INFO 1789 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-08-26 08:21:51.153 INFO 1789 --- [ restartedMain] t.f.notflying.NotflyingApplicationKt : Started NotflyingApplicationKt in 15.774 seconds (JVM running for 17.982)
If you enable debug logger by adding this line in application.properties:
logging.level.org.flywaydb=DEBUG
It will show you the exact path :
2019-08-26 08:30:31.661 DEBUG 1996 --- [ restartedMain] o.f.c.i.s.classpath.ClassPathScanner : Scanning URL: file:/mnt/c/Users/bleug/Desktop/notflying/build/resources/main/db/migration
Try to run it from a path with no space.
Edit:
Use gradle to run the project
It might be a long shot but still:
Can you try editing the path provided to flyway scripts to use backslash instead of forward slash?
flyway.locations=classpath:db\migration
or even
flyway.locations=filesystem=C:\Users\pupeno\Temporary\notflying\src\main\resources\db\migration
I've noticed that you are running your application in a Windows environment. It might be that Gradle does some magic regarding the default values but IntelliJ doesn't.
The answer by Nick was correct that migrations weren't being copied into the build/resources folder.
I work around this by adding the following to my script:
tasks.withType(org.flywaydb.gradle.task.AbstractFlywayTask) {
dependsOn processResources
}
Not sure why the Flyway gradle plugin doesn't do that.

Whitelabel error page on localhost:8080\sendMesssage?

I have just started Springboot with Twilio but for some reason when I run the localhost\sendMessage command I get the Whitelabel error Page. When I run the below code the test concludes successfully:
package com.example.demo
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestMapping
#RestController
public class SMSController{
#RequestMapping( "/")
fun helloSpringBoot() = "Hello Spring Boot!"
}
This is the result of the code above:
But when I run the below code with the localhost:8080\sendMessage I get the screenshot that follows the code:
package com.example.demo
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestMapping
import com.twilio.http.TwilioRestClient
import com.twilio.rest.api.v2010.account.MessageCreator
import com.twilio.type.PhoneNumber
#RestController
public class SMSController{
#RequestMapping("/sendMessage")
fun sendMessage(){
val client = TwilioRestClient.Builder(
System.getenv("ACCOUNT_SID"),
System.getenv("AUTH_TOKEN")).build()
val message = MessageCreator(
PhoneNumber(System.getenv("+1..........")),
PhoneNumber("+1.........."),
"Lambda is annoying..Sigh"
).create(client)
}
}
Am I missing something?
I have added my Stack TRace:
"C:\Program Files\Java\jdk1.8.0_25\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.1\lib\idea_rt.jar=25281:C:\Program Files\JetBrains\IntelliJ IDEA 2019.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Users\Jevon\IdeaProjects\demo\out\production\classes;C:\Users\Jevon\IdeaProjects\demo\out\production\resources;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.twilio.sdk\twilio\7.17.9\8de7649313c8fa3dfcbd215b6c0300ca1c4184f5\twilio-7.17.9.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\2.1.4.RELEASE\a4659d55f57421a5ef122cb670b7b544ef8190e8\spring-boot-starter-web-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\2.1.4.RELEASE\247d7c2efae986f310a29e9fef7174adc91d0835\spring-boot-starter-json-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.1.4.RELEASE\8fa436ef4e273cb476d5dc3aa73701a8837460af\spring-boot-starter-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.21\d0d5ff2ac2ebd8a42697af41e20fc225a23c5d3b\kotlin-reflect-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.3.21\d0634d54452abc421db494ad32dd215e6591c49f\kotlin-stdlib-jdk8-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\18.0\cce0823396aa693798f8882e64213b1772032b09\guava-18.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\joda-time\joda-time\2.10.1\9ac3dbf89dbf2ee385185dd0cd3064fe789efee0\joda-time-2.10.1.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\io.jsonwebtoken\jjwt\0.4\61ce246d937a0fd3acf06d3bef5fc9e3933ae812\jjwt-0.4.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpclient\4.5.8\c27c9d6f15435dc2b6947112027b418b0eef32b9\httpclient-4.5.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.4.11\de748cf874e4e193b42eceea9fe5574fabb9d4df\httpcore-4.4.11.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\2.9.8\bcd02aa9195390e23747ed40bf76be869ad3a2fb\jackson-datatype-jdk8-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.9.8\28ad1bced632ba338e51c825a652f6e11a8e6eac\jackson-datatype-jsr310-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-parameter-names\2.9.8\c4eef0e6e20d60fb27af4bc4770dba7bcc3f6de6\jackson-module-parameter-names-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.9.8\11283f21cc480aa86c4df7a0a3243ec508372ed2\jackson-databind-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.9.8\f5a654e4675769c716e5b387830d19b501ca191\jackson-core-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.9.0\7c10d545325e3a6e72e06381afe469fd40eb701\jackson-annotations-2.9.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.xml.bind\jaxb-api\2.3.1\8531ad5ac454cc2deb9d4d32c40c4d7451939b5d\jaxb-api-2.3.1.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-tomcat\2.1.4.RELEASE\3b0c04450d86fc29c9fdad555b4555e553a4008\spring-boot-starter-tomcat-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.hibernate.validator\hibernate-validator\6.0.16.Final\ad9557c558972093c0567a2a1f224f318c00f650\hibernate-validator-6.0.16.Final.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\5.1.6.RELEASE\cf4ea53740c93e0b8ff951ef0a3eaf154c74dbd0\spring-webmvc-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.1.6.RELEASE\4e15a24feba0581a02efd508af03a15b05570bd4\spring-web-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.1.4.RELEASE\d5f8b3f7835a23b4dfd8d1489d265c1e426e317b\spring-boot-autoconfigure-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.1.4.RELEASE\5ad0355a8c810b32b9221b9b92746b51c983337f\spring-boot-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\2.1.4.RELEASE\2fb669a89cd65b275be20ab755c3742399395dff\spring-boot-starter-logging-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.3.2\934c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.1.6.RELEASE\7b9e80ab68ee91ca0462a0eb2c58a9d957788b\spring-context-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.1.6.RELEASE\a473d4bca7295f2b90522594e413f9e19107c1d2\spring-aop-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.1.6.RELEASE\90d2f4bf7eced108de0b5bf617abb2b13a6206a3\spring-beans-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.1.6.RELEASE\50fe4080029e43e7612e50fb4d7c7c43e95bf03c\spring-expression-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.1.6.RELEASE\9329591e728ef9844911e082e399f4fc3e3ecb37\spring-core-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.3.21\d207ce2c9bcf17dc8e51bab4dbfdac4d013e7138\kotlin-stdlib-jdk7-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.21\4bcc2012b84840e19e1e28074284cac908be0295\kotlin-stdlib-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.11.2\6d37bf7b046c0ce2669f26b99365a2cfa45c4c18\log4j-to-slf4j-2.11.2.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.23\ec62d74fe50689c28c0ff5b35d3aebcaa8b5be68\snakeyaml-1.23.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.26\8031352b2bb0a49e67818bf04c027aa92e645d5c\jul-to-slf4j-1.7.26.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.26\77100a62c2e6f04b53977b9f541044d7d722693d\slf4j-api-1.7.26.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\commons-codec\commons-codec\1.11\3acb4705652e16236558f0f4f2192cc33c3bd189\commons-codec-1.11.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.activation\javax.activation-api\1.2.0\85262acf3ca9816f9537ca47d5adeabaead7cb16\javax.activation-api-1.2.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-websocket\9.0.17\a786505cc2697f7f2d8693c0c318270cc8addd92\tomcat-embed-websocket-9.0.17.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\9.0.17\aacb92c34eb2e88f38a060c9fcaaae329a79c9ca\tomcat-embed-core-9.0.17.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\9.0.17\595fbb87426e23f27c71b267f22b6e7d2a91a2aa\tomcat-embed-el-9.0.17.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.validation\validation-api\2.0.1.Final\cb855558e6271b1b32e716d24cb85c7f583ce09e\validation-api-2.0.1.Final.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.3.2.Final\3789d00e859632e6c6206adc0c71625559e6e3b0\jboss-logging-3.3.2.Final.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.4.0\291658ac2ce2476256c7115943652c0accb5c857\classmate-1.4.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.1.6.RELEASE\a4ad3c98c7cc31357e94e12772c8e6449522bc5\spring-jcl-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.21\f30e4a9897913e53d778f564110bafa1fef46643\kotlin-stdlib-common-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.11.2\f5e9a2ffca496057d6891a3de65128efc636e26e\log4j-api-2.11.2.jar" com.example.demo.DemoApplicationKt
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.4.RELEASE)
2019-04-04 15:32:35.584 INFO 8012 --- [ main] com.example.demo.DemoApplicationKt : Starting DemoApplicationKt on Javy26 with PID 8012 (C:\Users\Jevon\IdeaProjects\demo\out\production\classes started by Jevon in C:\Users\Jevon\IdeaProjects\demo)
2019-04-04 15:32:35.596 INFO 8012 --- [ main] com.example.demo.DemoApplicationKt : No active profile set, falling back to default profiles: default
2019-04-04 15:32:35.828 WARN 8012 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2019-04-04 15:32:39.918 INFO 8012 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-04-04 15:32:39.970 INFO 8012 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-04 15:32:39.970 INFO 8012 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-04 15:32:40.214 INFO 8012 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-04 15:32:40.214 INFO 8012 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4486 ms
2019-04-04 15:32:41.275 INFO 8012 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-04 15:32:41.807 INFO 8012 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-04-04 15:32:41.811 INFO 8012 --- [ main] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 7.81 seconds (JVM running for 10.279)
2019-04-04 15:33:24.230 INFO 8012 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-04 15:33:24.230 INFO 8012 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-04-04 15:33:24.250 INFO 8012 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 20 ms
I went back through the Kotlin documentation rather than focus on the tutorial and made the necessary changes. Once that was done the code started working as it should. See changes below:
#RestController
public class SMSController{
#RequestMapping(value = ["/sendMessage"])
fun sendMessage(){
val client = TwilioRestClient.Builder("ACCOUNT_SID",
"AUTH_TOKEN").build()
val message = MessageCreator(
PhoneNumber("+1........"),
PhoneNumber("+1........"),
"Lambda is annoying..Sigh").create(client)
}
}

Resources