EDIT: it works if I disable transport client sniffing.
Settings settings = Settings.builder()
.put("cluster.name", clusterName)
.put("client.transport.sniff", false)
.build();
Any ideas how to fix it?
First of all, everything works fine in Ubuntu 20.04, but when I try to run the same project using Docker Desktop on Windows 10, 11, and macOS, it fails.
When the Spring service starts it tries to find the Elasticsearch node and it fails, the exception is the following:
2022-12-27 16:20:40.459 INFO 23752 --- [ main] o.e.p.PluginsService : no modules loaded
2022-12-27 16:20:40.459 INFO 23752 --- [ main] o.e.p.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2022-12-27 16:20:40.460 INFO 23752 --- [ main] o.e.p.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2022-12-27 16:20:40.460 INFO 23752 --- [ main] o.e.p.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2022-12-27 16:20:40.460 INFO 23752 --- [ main] o.e.p.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2022-12-27 16:20:40.460 INFO 23752 --- [ main] o.e.p.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2022-12-27 16:21:02.679 INFO 23752 --- [ main] c.u.OnStartup : -----> APPLICATION INITIALIZATION <-----
2022-12-27 16:21:02.679 INFO 23752 --- [ main] c.u.OnStartup : -----> SETTING TIMEZONE
2022-12-27 16:21:02.679 INFO 23752 --- [ main] c.u.OnStartup : -----> CREATE INDEXES AND MAPPINGS NOW
2022-12-27 16:21:02.683 ERROR 23752 --- [ main] c.u.OnStartup : Elasticsearch unavailable, skipping creating of indexes
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{CA1SJmWMQfe1sRIDTY_Lpw}{localhost}{127.0.0.1:9300}]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:371) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:405) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:394) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1247) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46) ~[elasticsearch-6.2.4.jar:6.2.4]
at com.mymy.service.services.impl.IndexAndTypeManagementServiceImpl.indexExists(IndexAndTypeManagementServiceImpl.java:65) ~[classes/:?]
at com.mymy.service.services.impl.IndexAndTypeManagementServiceImpl.createIndex(IndexAndTypeManagementServiceImpl.java:95) ~[classes/:?]
at com.mymy.OnStartup.createIndexes(OnStartup.java:87) ~[classes/:?]
at com.mymy.OnStartup.init(OnStartup.java:55) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_352]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_352]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_352]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_352]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:414) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) [spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) [spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) [spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at
The docker-compose file looks like:
version: '3.5'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
container_name: elasticsearch
ports:
- 9200:9200
- 9300:9300
environment:
- discovery.type=single-node
- cluster.name=mycluster
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- xpack.security.enabled=false
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- elastic_data:/usr/share/elasticsearch/data
kibana:
image: docker.elastic.co/kibana/kibana:6.2.4
container_name: kibana
environment:
SERVER_NAME: localhost
ELASTICSEARCH_URL: http://elasticsearch:9200/
ports:
- 5601:5601
volumes:
- kibana_data:/var/log
depends_on:
- elasticsearch
volumes:
elastic_data:
kibana_data:
Java version is 1.8. Any suggestion on how to fix it?
Elasticsearch is accessible via Elasticsearch tools in the browser.
The answer is to add the following environment variables to docker-compose.yaml of the elasticsearch service:
environment:
- discovery.type=single-node
- network.host=_local_,_site_
- network.publish_host=_local_
or to start the elasticsearch with the command:
command: elasticsearch -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_
Solution thanks to https://github.com/olivere/elastic-with-docker/
Related
I can able to run the JAR file from local. But When I did uploaded the code to the Ubuntu 18.4 server AWS EC2, I am not able to run the JAR file.
By saying java -jar MyjarfileName.jar
Getting Error -
Could not create the directory where the uploaded files will be stored.
Details Error -
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/ubuntu/echeckinfo-backend/target/seamlesscheque-api-0.0.1-SNAPSHOT.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/ubuntu/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v0.0.1-SNAPSHOT)
2022-06-20 16:44:41.543 INFO 21492 --- [ main] c.s.app.SeamlesschequeApiApplication : Starting SeamlesschequeApiApplication v0.0.1-SNAPSHOT on ip-172-26-5-71 with PID 21492 (/home/ubuntu/echeckinfo-backend/target/seamlesscheque-api-0.0.1-SNAPSHOT.jar started by ubuntu in /home/ubuntu/echeckinfo-backend/target)
2022-06-20 16:44:41.566 INFO 21492 --- [ main] c.s.app.SeamlesschequeApiApplication : No active profile set, falling back to default profiles: default
2022-06-20 16:44:41.717 INFO 21492 --- [ main] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-06-20 16:44:41.718 INFO 21492 --- [ main] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-06-20 16:44:45.398 INFO 21492 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2022-06-20 16:44:45.402 INFO 21492 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2022-06-20 16:44:45.817 INFO 21492 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 407ms. Found 25 repository interfaces.
2022-06-20 16:44:46.706 INFO 21492 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'seamlesschequeApiApplication' of type [com.seamlesscheque.app.SeamlesschequeApiApplication$$EnhancerBySpringCGLIB$$be13dd17] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-06-20 16:44:47.528 INFO 21492 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
2022-06-20 16:44:47.602 INFO 21492 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-06-20 16:44:47.603 INFO 21492 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2022-06-20 16:44:47.621 INFO 21492 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2022-06-20 16:44:47.792 INFO 21492 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-06-20 16:44:47.793 INFO 21492 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6075 ms
2022-06-20 16:44:48.534 INFO 21492 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[139.59.18.83:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2022-06-20 16:44:48.799 INFO 21492 --- [.59.18.83:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:6108}] to 139.59.18.83:27017
2022-06-20 16:44:48.833 INFO 21492 --- [.59.18.83:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=139.59.18.83:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[5, 0, 0]}, minWireVersion=0, maxWireVersion=13, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=29872868}
2022-06-20 16:44:50.226 INFO 21492 --- [ main] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:6109}] to 139.59.18.83:27017
2022-06-20 16:44:51.877 WARN 21492 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fileController': Unsatisfied dependency expressed through field 'fileService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileServiceImpl' defined in URL [jar:file:/home/ubuntu/echeckinfo-backend/target/seamlesscheque-api-0.0.1-SNAPSHOT.jar!/com/seamlesscheque/app/service/FileServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.seamlesscheque.app.service.FileServiceImpl]: Constructor threw exception; nested exception is com.seamlesscheque.app.exception.FileStorageException: Could not create the directory where the uploaded files will be stored.
2022-06-20 16:44:51.890 INFO 21492 --- [ main] org.mongodb.driver.connection : Closed connection [connectionId{localValue:2, serverValue:6109}] to 139.59.18.83:27017 because the pool has been closed.
2022-06-20 16:44:51.895 INFO 21492 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-06-20 16:44:51.943 INFO 21492 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-20 16:44:51.955 ERROR 21492 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fileController': Unsatisfied dependency expressed through field 'fileService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileServiceImpl' defined in URL [jar:file:/home/ubuntu/echeckinfo-backend/target/seamlesscheque-api-0.0.1-SNAPSHOT.jar!/com/seamlesscheque/app/service/FileServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.seamlesscheque.app.service.FileServiceImpl]: Constructor threw exception; nested exception is com.seamlesscheque.app.exception.FileStorageException: Could not create the directory where the uploaded files will be stored.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at com.seamlesscheque.app.SeamlesschequeApiApplication.main(SeamlesschequeApiApplication.java:37) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_312]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_312]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_312]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_312]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [spring-boot-thin-launcher-1.0.23.RELEASE-exec.jar:1.0.23.RELEASE]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [spring-boot-thin-launcher-1.0.23.RELEASE-exec.jar:1.0.23.RELEASE]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [spring-boot-thin-launcher-1.0.23.RELEASE-exec.jar:1.0.23.RELEASE]
at org.springframework.boot.loader.thin.ThinJarLauncher.launch(ThinJarLauncher.java:193) [spring-boot-thin-launcher-1.0.23.RELEASE-exec.jar:1.0.23.RELEASE]
at org.springframework.boot.loader.thin.ThinJarLauncher.main(ThinJarLauncher.java:140) [spring-boot-thin-launcher-1.0.23.RELEASE-exec.jar:1.0.23.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_312]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_312]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_312]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_312]
at org.springframework.boot.loader.wrapper.ThinJarWrapper.launch(ThinJarWrapper.java:140) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.wrapper.ThinJarWrapper.main(ThinJarWrapper.java:107) [seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileServiceImpl' defined in URL [jar:file:/home/ubuntu/echeckinfo-backend/target/seamlesscheque-api-0.0.1-SNAPSHOT.jar!/com/seamlesscheque/app/service/FileServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.seamlesscheque.app.service.FileServiceImpl]: Constructor threw exception; nested exception is com.seamlesscheque.app.exception.FileStorageException: Could not create the directory where the uploaded files will be stored.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:304) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:285) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1308) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:273) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1237) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
... 34 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.seamlesscheque.app.service.FileServiceImpl]: Constructor threw exception; nested exception is com.seamlesscheque.app.exception.FileStorageException: Could not create the directory where the uploaded files will be stored.
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:300) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
... 47 common frames omitted
Caused by: com.seamlesscheque.app.exception.FileStorageException: Could not create the directory where the uploaded files will be stored.
at com.seamlesscheque.app.service.FileServiceImpl.<init>(FileServiceImpl.java:46) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_312]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_312]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_312]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_312]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
... 49 common frames omitted
Caused by: java.nio.file.AccessDeniedException: /home/echeckpiiweb
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[na:1.8.0_312]
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[na:1.8.0_312]
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[na:1.8.0_312]
at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384) ~[na:1.8.0_312]
at java.nio.file.Files.createDirectory(Files.java:674) ~[na:1.8.0_312]
at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) ~[na:1.8.0_312]
at java.nio.file.Files.createDirectories(Files.java:767) ~[na:1.8.0_312]
at com.seamlesscheque.app.service.FileServiceImpl.<init>(FileServiceImpl.java:44) ~[seamlesscheque-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
... 54 common frames omitted
I have solve this problem. In order to run this -
First we have to run our project in sudo mode.
sudo java -jar myjarfileName.jar
Note -
Make sure you have java installed
sudo apt-update
sudo apt-get install openjdk-8-jre openjdk-8-jdk)
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
java -version
Make sure you have maven installed
sudo apt-get install maven
mvn -version
Make sure you can able to build your application
Note - It will take some of the time to start. Once its start, you can ran your application, it will create all the directory, you can remove sudo, and ran it again. by saying -
java -jar myjarfileName.jar
I am using spring boot 2.5.3 and postgreSQL for backend.
I want this app to run on localhost:5000/api/v1/customers as well as from docker-compose.
application.properties:
server.port=5000
#Database setup
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://localhost:5432/customers
spring.datasource.username=postgres
spring.datasource.password=postgres
This works with localhost, with mvn spring-boot:run
But, when I use the following application.properties settings from localhost to db
server.port=5000
#Database setup
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://db:5432/customers
spring.datasource.username=postgres
spring.datasource.password=postgres
Dockerfile
FROM maven:3.8.1-openjdk-11-slim
COPY ./target/customer-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
docker-compose.yml
version: '3.1'
services:
app:
container_name: customer-container
image: customer-image:v1
build: ./
ports:
- "5000:5000"
depends_on:
- db
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=customers
I cannot connect to localhost:5000/api/v1/customers after mvn spring-boot:run
Error:
org.postgresql.util.PSQLException: Connection to db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:303) ~[postgresql-42.2.23.jar:42.2.23]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.23.jar:42.2.23]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.23.jar:42.2.23]
at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.23.jar:42.2.23]
at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.23.jar:42.2.23]
Tried to create a docker image docker build -t customer-image:v1 .
, and run docker-compose build docker-compose up there are no error.
Logs says it is running on port 5000.
customer-container | 2021-08-29 12:43:42.053 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
customer-container | 2021-08-29 12:43:42.068 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
customer-container | 2021-08-29 12:43:42.069 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.50]
customer-container | 2021-08-29 12:43:42.189 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
customer-container | 2021-08-29 12:43:42.190 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1876 ms
customer-container | 2021-08-29 12:43:42.487 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
customer-container | 2021-08-29 12:43:42.567 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
customer-container | 2021-08-29 12:43:42.702 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
customer-container | 2021-08-29 12:43:42.827 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
customer-container | 2021-08-29 12:43:42.970 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
customer-container | 2021-08-29 12:43:42.995 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
customer-container | 2021-08-29 12:43:43.631 WARN 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
customer-container | 2021-08-29 12:43:43.631 WARN 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : table "customer" does not exist, skipping
customer-container | 2021-08-29 12:43:43.642 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
customer-container | 2021-08-29 12:43:43.656 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
customer-container | 2021-08-29 12:43:44.252 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
customer-container | 2021-08-29 12:43:44.991 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 5000 (http) with context path ''
customer-container | 2021-08-29 12:43:45.290 INFO 1 --- [ main] c.p.customer.CustomerApplication : Started CustomerApplication in 5.654 seconds (JVM running for 6.531)
This works localhost:5000/api/v1/customers when docker-compose is up.
Is there a way we can have condtional name for host in this line?Is there any other way?
spring.datasource.url=jdbc:postgresql://db:5432/customers
Since the host development environment and the container runtime environment are different, you can use environment variables to differentiate between them. Spring Boot knows how to set Spring properties from environment variables. So I'd recommend:
In your application.properties file, set spring.datasource.url to the localhost URL you'd use in development.
In your Compose setup, set the SPRING_DATASOURCE_URL environment variable to the name specific to that Compose setup
version: '3.8'
services:
db: { ... }
app:
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/customers
...
Do not create a separate Spring profile per environment; you would not want to recompile your jar file if you changed the database name or password, or deployed this in Kubernetes, or used a cloud-hosted database like Amazon RDS, or...
So, you want to be able to run both locally and from docker?
If that's the case, you need to extract the database connection string to an environment variable that you set at runtime
spring.datasource.url = ${DB_HOST}:${DB_PORT}/
spring.datasource.username = ${DB_USERNAME}
spring.datasource.password = ${DB_PASSWD}
Or you can introduce two different property files that get set from a Spring profile, which you also would set at runtime; Refer SPRING_PROFILES_ACTIVE environment variable
Based on what I see, you are not supposed to use localhost on spring.datasource.url because your docker is within the container itself, you should be using
jdbc:postgresql://host.docker.internal:5432/customers instead. For more details, you can view from this link https://docs.docker.com/desktop/windows/networking/#i-cannot-ping-my-containers
Is there a way we can have condtional name for host in this line?Is there any other way?
As for this, it would be prefered to set it as an environmetn variable on your docker compose file and connect using dbconn url
If you are using linux as your operating system on which you are running your docker , you can set this property
network_mode: host
on both the containers, this will attach your container's port to your localhost port.
You will need to remove the port forwarding config for this to work.
I have a Spring boot app that is containerized and published to the docker hub. I have this docker-copmse.yml:-
version: '3.1'
services:
postgres:
image: postgres
container_name: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=mydb
profile_back:
container_name: profile_back
image: madsum/profile_back
ports:
- "8080:8080"
depends_on:
- postgres
My spring boot application.propertiese:-
#spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.url=jdbc:postgresql://postgres:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
I don't know what is the correct spring.datasource.url. I tried both jdbc:postgresql://localhost:5432/mydb and jdbc:postgresql://postgres:5432/mydb .Both give connection error. Btw, container runs perfectly. I can verify by it as docker exec -it --user postgres dbpostgresql sh . I can see the database created. What is the correct way to connect it?
Updated question:-
I am using flyway. Here is the exception now:-
ound 1 JPA repository interfaces.
2020-03-06 09:33:01.939 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-06 09:33:01.949 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-06 09:33:01.949 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-06 09:33:01.997 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-06 09:33:01.998 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1180 ms
2020-03-06 09:33:02.118 INFO 1 --- [ main] o.f.c.internal.license.VersionPrinter : Flyway Community Edition 6.0.8 by Redgate
2020-03-06 09:33:02.124 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-03-06 09:33:02.127 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
2020-03-06 09:33:02.130 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-03-06 09:33:02.141 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-06 09:33:02.145 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar!/:5.2.4.RELEASE]
Carefully reading the exception, gives you a valuable hint:
Invocation of init method failed; nested exception is
java.lang.RuntimeException: Driver org.postgresql.Driver claims to not
accept jdbcUrl,
jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 2020-03-06
So it seems your application tries to connect to an in-memory H2 database and not to PostgreSQL.
Do you maybe use different profiles for your application and forgot to set the production profile? Otherwise, you can get rid of the H2 dependency in your pom.xml/build.gradle if you don't need it
Try using 127.0.0.1 instead of localhost
I have 2 different projects as below
Root Project
|
|--commons(Library)
| |--Gender.kt(Enum)
|
|--user-manager(uses commons library)
| |--UserProfile.kt (JPA #Entity which uses Gender as a field)
If I move the Gender.kt in user-manager project, everything works fine. The moment I move it to commons library, I get the following error while running the Spring Boot application
17:21:17: Executing task 'bootRun'...
> Task :common:compileKotlin
> Task :common:compileJava NO-SOURCE
> Task :common:processResources UP-TO-DATE
> Task :common:classes UP-TO-DATE
> Task :common:inspectClassesForKotlinIC
> Task :common:jar SKIPPED
> Task :user-manager:compileKotlin
> Task :user-manager:compileJava NO-SOURCE
> Task :user-manager:processResources UP-TO-DATE
> Task :user-manager:classes UP-TO-DATE
> Task :user-manager:bootRun
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.M1)
2019-03-18 17:21:26.049 INFO 18244 --- [ main] c.s.u.UserServiceApplicationKt : Starting UserServiceApplicationKt on LPTP-BLR-Nayan with PID 18244 (E:\Repos\HC7\user-manager\build\classes\kotlin\main started by nayan.kurude in E:\Repos\HC7\user-manager)
2019-03-18 17:21:26.056 INFO 18244 --- [ main] c.s.u.UserServiceApplicationKt : No active profile set, falling back to default profiles: default
2019-03-18 17:21:28.540 INFO 18244 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-03-18 17:21:28.806 INFO 18244 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 239ms. Found 3 repository interfaces.
2019-03-18 17:21:29.810 INFO 18244 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$1be4cc54] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-18 17:21:31.356 INFO 18244 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-03-18 17:21:31.407 INFO 18244 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-03-18 17:21:31.408 INFO 18244 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2019-03-18 17:21:31.432 INFO 18244 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_181\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\nodejs\;C:\Program Files\apache-maven-3.6.0\bin;C:\Program Files\Java\jdk1.8.0_181\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Users\nayan.kurude\AppData\Local\Microsoft\WindowsApps;C:\Users\nayan.kurude\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\nayan.kurude\AppData\Roaming\npm;C:\Gradle\bin;;.]
2019-03-18 17:21:31.635 INFO 18244 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-03-18 17:21:31.636 INFO 18244 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5466 ms
2019-03-18 17:21:32.681 INFO 18244 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-03-18 17:21:34.375 INFO 18244 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-03-18 17:21:34.608 INFO 18244 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-03-18 17:21:34.952 INFO 18244 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.0.Final}
2019-03-18 17:21:34.957 INFO 18244 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-03-18 17:21:35.408 INFO 18244 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-03-18 17:21:35.672 INFO 18244 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.SQLServer2012Dialect
2019-03-18 17:21:36.074 WARN 18244 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/simbalarry/common/enums/Gender
2019-03-18 17:21:36.075 INFO 18244 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-03-18 17:21:36.082 INFO 18244 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2019-03-18 17:21:36.088 INFO 18244 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-03-18 17:21:36.113 INFO 18244 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-18 17:21:36.125 ERROR 18244 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/simbalarry/common/enums/Gender
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.2.0.M1.jar:2.2.0.M1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:785) [spring-boot-2.2.0.M1.jar:2.2.0.M1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:407) [spring-boot-2.2.0.M1.jar:2.2.0.M1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.2.0.M1.jar:2.2.0.M1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1278) [spring-boot-2.2.0.M1.jar:2.2.0.M1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1266) [spring-boot-2.2.0.M1.jar:2.2.0.M1]
at com.simbalarry.usermanager.UserServiceApplicationKt.main(UserServiceApplication.kt:13) [main/:na]
Caused by: java.lang.NoClassDefFoundError: com/simbalarry/common/enums/Gender
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_181]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_181]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_181]
at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredMethodProperties(JavaXClass.java:95) ~[hibernate-commons-annotations-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:112) ~[hibernate-commons-annotations-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:104) ~[hibernate-commons-annotations-5.1.0.Final.jar:5.1.0.Final]
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:252) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:785) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:903) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:934) ~[hibernate-core-5.4.0.Final.jar:5.4.0.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
... 16 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.simbalarry.common.enums.Gender
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_181]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_181]
... 37 common frames omitted
> Task :user-manager:bootRun FAILED
w: Detected multiple Kotlin daemon sessions at build\kotlin\sessions
FAILURE: Build failed with an exception.
As mentioned above I have a Gender.kt file which is in commons library and I am using it in JPA Entity class in user-manager module. The project compiles fine, but while running, it throws the exception as above.
Could anyone please help me with this?
Any help would be highly appreciated.
I created an new project with springboot2.2.0.M2 / Flyway 5.2.4 / Java8.
After try to start my project i got :
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.4.RELEASE)
2019-04-22 13:36:54.574 INFO 17268 --- [ restartedMain] com.example.demo214.Demo214Application : Starting Demo214Application on xx-MacBook-Pro.local with PID 17268
2019-04-22 13:36:54.577 INFO 17268 --- [ restartedMain] com.example.demo214.Demo214Application : The following profiles are active: dev
2019-04-22 13:36:54.665 INFO 17268 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-04-22 13:36:54.665 INFO 17268 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-04-22 13:36:55.731 WARN 17268 --- [ restartedMain] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.example.demo214]' package. Please check your configuration.
2019-04-22 13:36:55.939 INFO 17268 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-04-22 13:36:55.943 INFO 17268 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-04-22 13:36:55.983 INFO 17268 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9ms. Found 0 repository interfaces.
2019-04-22 13:36:56.412 INFO 17268 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$631e07b5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-22 13:36:56.875 INFO 17268 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-04-22 13:36:56.901 INFO 17268 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-22 13:36:56.902 INFO 17268 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-22 13:36:57.103 INFO 17268 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-22 13:36:57.103 INFO 17268 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2438 ms
2019-04-22 13:36:57.257 INFO 17268 --- [ restartedMain] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2019-04-22 13:36:57.413 INFO 17268 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
2019-04-22 13:36:58.008 INFO 17268 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\
/ |
3.1.0
Mon Apr 22 13:36:58 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2019-04-22 13:36:59.143 WARN 17268 --- [ 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-04-22 13:36:59.144 INFO 17268 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2019-04-22 13:36:59.170 INFO 17268 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed
2019-04-22 13:36:59.172 INFO 17268 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-04-22 13:36:59.184 INFO 17268 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-22 13:36:59.197 ERROR 17268 --- [ 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.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at com.example.demo214.Demo214Application.main(Demo214Application.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.4.RELEASE.jar:2.1.4.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.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.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.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.checkLocationExists(FlywayAutoConfiguration.java:194) ~[spring-boot-autoconfigure-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:153) ~[spring-boot-autoconfigure-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$e31bd555.CGLIB$flyway$0(<generated>) ~[spring-boot-autoconfigure-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$e31bd555$$FastClassBySpringCGLIB$$169da02e.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$e31bd555.flyway(<generated>) ~[spring-boot-autoconfigure-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
... 27 common frames omitted
Process finished with exit code 1
I have a init sql under db/migration with name: V1.0.0__init.sql (just one line in it: use mydb;)
my flyway configuration in yml (ignore other datasource):
spring:
flyway:
baseline-on-migrate: true
locations: classpath:db/migration
I tried to debug it, found the FlywayAutoConfiguratioin.hasAtLeastOneLocation() always return false, it means not found the location (but the location looks like right in debugger), see the following screenshot:
appreciate any kind help :)
Make sure that you have not accidentally created a folder with the name db.migration, as opposed to the folders db/migration.
Intellij will show both as db.migration in the project files view, when you have the option "Compact Middle Packages" enabled.
Try to use in Spring Boot application.properties:
spring.flyway.check-location = false
It switches off Flyway migration scripts presents check.
Also see a set of default Flyway variables for Spring Boot
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
Mostly it happen because of copy paste. Make sure that you copy the script after creating folder structure like below
resources/
db/
migration/
_init.sql
IntelliJ shows both db.migration and db/migration to same as db.migration.
You can actual structure by clicking on top right gear sign and tick of flatten package. Hope this helps.
I got the same problem and for me helped creating new empty file in migration folder :
for example - init.sql
I already created db.migration folders exactly but still got this error, however I added this and it seemed like it worked
spring.flyway.check-location = false
For me the name of the scheme V1_1_schema.sql was wrong.
Changing it to V1_1__schema.sql solved the location issue.
Seems like Flyway requires double underscore __ in name prefix.
I solved this problem like this: first we create a "db folder" in "resources", then we create any file in the "db folder", then we create a "migration" subdirectory and already in it we create our migration file