is there any conflict between spring-boot-starter-parent version 2 and spring-security-jwt and spring-security-oauth2 - spring-boot

I am trying to fix an issue I am facing with Spring Boot + Java 8 and Hibernate (my original question regard this issue is org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type java.time.LocalDateTime).
Since I read Since 5.2, "the hibernate-java8 module has been merged into hibernate-core and the Java 8 date/time types are now natively supported." from How to persist JSR-310 types with Spring Data JPA?, I tried to update all my Spring Boot dependencies to the most recent.
I mean, my parent pom was before:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
and I changed to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
The purpose to do that was take advantage of "...now natively supported..." as mentioned above assuming it could fix any conflict I could be facing with datetime.
Now I am facing another issue with
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
saying: Project build error: 'dependencies.dependency.version' for org.springframework.security.oauth:spring-security-oauth2:jar is
missing (same for org.springframework.security:spring-security-jwt:jar).
How can I fix that specific issue with org.springframework.security:spring-security-jwt:jar and org.springframework.security.oauth:spring-security-oauth2:jar ?
*** edited, after I change the version as mentioned above, I am getting
:: Spring Boot :: (v1.5.6.RELEASE)
2018-03-26 17:53:10.490 INFO 1161 --- [ restartedMain] br.com.moving.MovingApiApplication : Starting MovingApiApplication on fulls-iMac.home with PID 1161 (/Users/accountname/WSs/ws_servicos_prontos/api-moving/target/classes started by accountname in /Users/accountname/WSs/ws_servicos_prontos/api-moving)
2018-03-26 17:53:10.492 INFO 1161 --- [ restartedMain] br.com.moving.MovingApiApplication : The following profiles are active: ${envspring}
2018-03-26 17:53:10.607 INFO 1161 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#64f45797: startup date [Mon Mar 26 17:53:10 BRT 2018]; root of context hierarchy
2018-03-26 17:53:11.879 INFO 1161 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'commandLineRunner' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=apiSecurityApplication; factoryMethodName=commandLineRunner; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [br/com/moving/ApiSecurityApplication.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=movingApiApplication; factoryMethodName=commandLineRunner; initMethodName=null; destroyMethodName=(inferred); defined in br.com.moving.MovingApiApplication]
2018-03-26 17:53:12.276 INFO 1161 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2018-03-26 17:53:13.017 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$501c7c5b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.096 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$e8ca4495] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.110 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.115 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#616c515f' of type [org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.122 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$d9ee747] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.157 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.212 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.218 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration' of type [org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration$$EnhancerBySpringCGLIB$$766385b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.254 INFO 1161 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'resourceServerProperties' of type [org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-26 17:53:13.831 INFO 1161 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9000 (http)
2018-03-26 17:53:13.847 INFO 1161 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-03-26 17:53:13.848 INFO 1161 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2018-03-26 17:53:13.972 INFO 1161 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-03-26 17:53:13.972 INFO 1161 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3368 ms
2018-03-26 17:53:14.201 INFO 1161 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-26 17:53:14.203 INFO 1161 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-03-26 17:53:14.203 INFO 1161 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-03-26 17:53:14.263 WARN 1161 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "${envspring}" are currently active).
2018-03-26 17:53:14.270 INFO 1161 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-03-26 17:53:14.298 INFO 1161 --- [ restartedMain] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-03-26 17:53:14.303 ERROR 1161 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "${envspring}" are currently active).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.743 s
[INFO] Finished at: 2018-03-26T17:53:14-03:00
[INFO] ------------------------------------------------------------------------
It sounds strange see v1.5.6.RELEASE in logs while I setup 2.0.0.RELEASE for spring-boot-starter-parent

Spring Boot 2.0 migration guide says that
Functionality from the Spring Security OAuth project is being migrated to core Spring Security. Dependency management is no longer provided for that dependency and Spring Boot 2 provides OAuth 2.0 client support via Spring Security 5.
So you should specify jwt and oauth2 dependencies manually.
<spring-security-oauth2.version>2.3.3.RELEASE</spring-security-oauth2.version>
<spring-security-jwt.version>1.0.9.RELEASE</spring-security-jwt.version>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>${spring-security-oauth2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>${spring-security-jwt.version}</version>
</dependency>

Related

Spring Boot Application gets stuck on "Hikari-Pool-1 - Starting..."

I'm trying to run Spring Boot application connected to PostgreSQL database. However, when it comes to Hikari connection pool initializing, it just gets stuck and nothing goes on. HikariPool-1 - Starting... appears in logs and then nothing happens.
Logs:
2018-07-09 15:32:48.475 INFO 21920 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#68999068: startup date [Mon Jul 09 15:32:48 ALMT 2018]; root of context hierarchy
2018-07-09 15:32:48.736 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$1b7bd026] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-07-09 15:32:49.207 INFO 21920 --- [ main] o.paperplane.todoapp.TodoappApplication : No active profile set, falling back to default profiles: default
2018-07-09 15:32:49.217 INFO 21920 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#1b410b60: startup date [Mon Jul 09 15:32:49 ALMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#68999068
2018-07-09 15:32:49.763 INFO 21920 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Dbcp2; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Dbcp2.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]]
2018-07-09 15:32:50.046 INFO 21920 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=refresh; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=false; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]] with [Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]]
2018-07-09 15:32:50.212 INFO 21920 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=2203ab9b-5bb0-34f2-b496-2cbda1e334a2
2018-07-09 15:32:50.342 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ff61cd29] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.380 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$980f9563] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.389 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.393 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#309028af' of type [org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.397 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$bce43815] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.404 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.424 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$1b7bd026] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.692 INFO 21920 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-07-09 15:32:50.710 INFO 21920 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-07-09 15:32:50.710 INFO 21920 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-09 15:32:50.714 INFO 21920 --- [ost-startStop-1] 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_151\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\7-Zip;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;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\;D:\node_js\;C:\Program Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Local\GitHubDesktop\bin;C:\Users\User\AppData\Roaming\npm;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;;.]
2018-07-09 15:32:50.817 INFO 21920 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-07-09 15:32:50.817 INFO 21920 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1600 ms
2018-07-09 15:32:51.784 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-07-09 15:32:51.786 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-07-09 15:32:51.786 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-07-09 15:32:51.885 INFO 21920 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
My pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.paperplane</groupId>
<artifactId>todoapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>todoapp</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
My apllication.properties:
spring.datasource.url=jdbc:postgresql://127.0.0.1:55491/TodoAppDatabase
spring.datasource.username=admin
spring.datasource.password=root
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.driver-class-name=org.postgresql.Driver
spring.datasource.hikari.maximum-pool-size=100
spring.data.jpa.repositories.enabled=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
How can I overcome this issue?
Normal postgresql port is 5432, so I assume you also configured it to 55491.
Double check this via your postgresql client using psql -h 127.0.0.1 -p 55491 -d TodoAppDatabase -U admin
At last you can put the HikariCP into DEBUG mode, so you can see what parameters its using.
If your properties file is really apllication.properties than this may also an issue because spring boot only picks up application.properties automatically.
Making below change in application.properties should work fine:
spring.datasource.url=jdbc:postgresql://localhost:5432/<dbName>
Also make sure, you have Fixed Port Number box unchecked, in the pgAdmin configuration BOX, refer the screenshot
In my case spring.datasource.hikari.initializationFailTimeout was set to a really high value, 3600000 (1 hour). This, in it self, was not a malconfiguration but it hid the real problem as the app was hanging on startup.
Once that value was adjusted, I got a much more understandable stack trace which led me to the conclusion that in this case I couldn't use the default MariaDB driver configuration that I probably got through a jHipster.
A very wierd problem that I so far only has seen with MySQL8 and Ubuntu 20 on AWS EC2. Locally I run Ubuntu and MySQL8 via Docker without issues.
It might not be able to connect to DB.
try restarting your DB instance and make sure it is accessible.
try passing this parameter when you run your jar file:
-Djava.security.egd=file:/dev/../dev/urandom
In my case it was a problem with a network connectivity. Make sure you can access your any configured servers if you got into this issue.
telnet host 5432 will let you connect to see if a route exists to the DB server.
in my case (windows 10), it took three steps:
stop the postgresql service running
open command prompt as administrator and kill any service on port 5432
restart the postgresql service from services window.
and you're good.
I had the same problem and solved this by removing the AUTO_SERVER=true line in the application.properties file, so after removing that the application runs as usual.
Remove the AUTO_SERVER=true in #spring.datasource.url=jdbc:... AUTO_SERVER=true
Whit this you loose the functionality to access the database from different sources like from the terminal, meaning you can't access the database from your terminal while your app is running (ie using the database)
But if you need AUTO_SERVER=true then please restart your pc, and with it the database will restart which might solve your problem (this is not a joke).
There could be several reasons why hikaripool-1 is taking a long time to start. One possibility is that there may be high traffic on the network or server, causing delays in processing requests.
Another possibility is that there may be technical issues with the software or hardware, which can also cause delays. It is recommended to check the logs and error messages for any clues about what might be causing the delay and to contact technical support for assistance if necessary.

Unable to hit rest service running with spring boot

I have configured restful webservice and hosted with the help of Spring Boot. But I'm not able to hit the service. And getting Response Status: -1 - Request Failed (Canceled or Timed-Out)
Logs:-
⁃ 2017-10-08 18:33:33.149 INFO 6806 --- [ main] com.mypleaks.PleaksRSApp : Starting PleaksRSApp on 3inmderaj1.local with PID 6806 (/Users/deraj/home/code/leaks-rs/mypleaks-rs/myPleaks-RS/target/classes started by deraj in /Users/deraj/home/code/leaks-rs/mypleaks-rs/myPleaks-RS)
⁃ 2017-10-08 18:33:33.155 INFO 6806 --- [ main] com.mypleaks.PleaksRSApp : No active profile set, falling back to default profiles: default
⁃ 2017-10-08 18:33:33.202 INFO 6806 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#311bf055: startup date [Sun Oct 08 18:33:33 IST 2017]; root of context hierarchy
⁃ 2017-10-08 18:33:33.998 INFO 6806 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'requestContextFilter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.class]] with [Root bean: class [org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
⁃ 2017-10-08 18:33:34.276 INFO 6806 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
⁃ 2017-10-08 18:33:34.372 INFO 6806 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$af71e9e1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
⁃ 2017-10-08 18:33:34.745 INFO 6806 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
⁃ 2017-10-08 18:33:34.756 INFO 6806 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
⁃ 2017-10-08 18:33:34.756 INFO 6806 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
Resource :-
Request:-
Response:-
It seems that you are using the annotations from the javax. package instead of the spring ones.
Try using #RestController on the class level and #RequestMapping on the method level (all other annotations should be from the spring package also):
#RestController
#RequestMapping(path = "/place")
public class PlaceResource{
#RequestMapping(method = RequestMethod.GET, path="/countries")
public Response getCountries(..){..}
}
Sorry Guys, Its was terrible mistake from my side. I had used below code in my application.
public class NotificationEngine implements InitializingBean {
#Override
public void afterPropertiesSet() throws Exception {"Here I was running some stupid endless process, Due to which the tomcat was not getting up completely and because of that Iwas getting this issue."}}
Please check that you have following dependency in your pom.xml, If it is not there please add it and re-run.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Error running gradle bootrun

I am trying to do gradle bootRun using IntelliJ, but this error appears:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command 'C:\Program Files\Java\jdk1.8.0_131\bin\java.exe'' finished with non-zero exit value 1
In the Console I have this:
2017-06-21 10:13:54.177 INFO 12008 --- [ main] com.nice_system.nicemedia.ApplicationKt : Starting ApplicationKt on DESKTOP-GHI2UHL with PID 12008 (started by Darja Strahlberg in C:\Users\Darja Strahlberg
\code\versuch\nto_niceMediaServer)
2017-06-21 10:13:54.182 INFO 12008 --- [ main] com.nice_system.nicemedia.ApplicationKt : No active profile set, falling back to default profiles: default
2017-06-21 10:13:54.310 INFO 12008 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5be6e01c: start
up date [Wed Jun 21 10:13:54 CEST 2017]; root of context hierarchy
2017-06-21 10:13:56.234 INFO 12008 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean:
class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$Ena
bleWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurat
ion$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframew
ork.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/re
st/webmvc/config/RepositoryRestMvcConfiguration.class]]
2017-06-21 10:13:57.102 INFO 12008 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframe
work.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$dc898557] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-06-21 10:13:57.776 INFO 12008 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http)
2017-06-21 10:13:57.797 INFO 12008 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-06-21 10:13:57.800 INFO 12008 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-06-21 10:13:58.025 INFO 12008 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-06-21 10:13:58.025 INFO 12008 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3719 ms
2017-06-21 10:13:58.319 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-21 10:13:58.325 INFO 12008 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally u
nnecessary.
2017-06-21 10:14:00.929 ERROR 12008 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
This is my build.gradle file:
plugins {
id "org.jetbrains.kotlin.jvm" version "1.1.2"
id "org.jetbrains.kotlin.plugin.noarg" version "1.1.2"
id "org.jetbrains.kotlin.plugin.jpa" version "1.1.2"
id "org.springframework.boot" version "1.5.3.RELEASE"}
jar {
baseName = 'nicemedia-api'
version = '0.1.0'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-data-rest"
testCompile "org.springframework.boot:spring-boot-starter-test"
runtime "mysql:mysql-connector-java:6.0.6"
runtime "com.h2database:h2"
}
repositories {
mavenCentral()
}

cannot find DiscoveryClient bean error in spring boot

2017-03-16 16:09:08.821 INFO 9104 --- [ main] com.hello.EurekaClientApplication : No active profile set, falling back to default profiles: default
2017-03-16 16:09:08.848 INFO 9104 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5dcd8c7a: startup date [Thu Mar 16 16:09:08 CDT 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#441772e
2017-03-16 16:09:09.873 INFO 9104 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'hystrixFeature' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerConfiguration$HystrixWebConfiguration; factoryMethodName=hystrixFeature; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerConfiguration$HystrixWebConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerConfiguration; factoryMethodName=hystrixFeature; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerConfiguration.class]]
2017-03-16 16:09:10.364 WARN 9104 --- [ main] o.s.c.a.ConfigurationClassPostProcessor : Cannot enhance #Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static #Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2017-03-16 16:09:10.701 INFO 9104 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=d0eb8cfd-bd5b-3565-9f63-f671e896f6be
2017-03-16 16:09:10.736 INFO 9104 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-03-16 16:09:11.312 INFO 9104 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$94394ff6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-03-16 16:09:12.091 INFO 9104 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-03-16 16:09:12.128 INFO 9104 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-03-16 16:09:12.130 INFO 9104 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.11
2017-03-16 16:09:12.546 INFO 9104 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-03-16 16:09:12.547 INFO 9104 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3699 ms
2017-03-16 16:09:13.191 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'proxyStreamServlet' to [/proxy.stream]
2017-03-16 16:09:13.193 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-03-16 16:09:13.198 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]
2017-03-16 16:09:13.199 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-03-16 16:09:13.199 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-03-16 16:09:13.200 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-03-16 16:09:13.200 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-03-16 16:09:13.200 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-03-16 16:09:13.200 INFO 9104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-03-16 16:09:13.269 WARN 9104 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaClientApplication': Unsatisfied dependency expressed through field 'clientservice'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clientService' defined in file [C:\Users\Mike\workspace\Eureka_client\target\classes\com\hello\ClientService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.discovery.DiscoveryClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2017-03-16 16:09:13.306 INFO 9104 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2017-03-16 16:09:13.404 INFO 9104 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-03-16 16:09:13.745 ERROR 9104 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.hello.ClientService required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
Action:
Consider defining a bean of type 'com.netflix.discovery.DiscoveryClient' in your configuration.
package com.hello;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.stereotype.Service;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
#EnableDiscoveryClient
#Service
public class ClientService {
private final DiscoveryClient disc;
public ClientService(DiscoveryClient disc){
this.disc=disc;
}
#HystrixCommand(fallbackMethod="disp")
public String serviceInstancesByApplicationName(){
return this.disc.getInstancesById("a-bootiful-client").toString();
}
public String disp(){
return "This is fall back method";
}
}
package com.hello;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
#EnableHystrix
#EnableHystrixDashboard
#EnableDiscoveryClient
#SpringBootConfiguration
#EnableAutoConfiguration
#ComponentScan
#RestController
public class EurekaClientApplication {
#Autowired
private ClientService clientservice;
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
#RequestMapping("/serv")
public String serviceInstancesByApplicationName(){
return clientservice.serviceInstancesByApplicationName();
}
}
i am trying to create a simple eureka service and client program and enable hystrix on that. but i am getting this error on the code
You imported wrong DiscoveryClient class in your code. DiscoveryClient from netflix is not provided as Spring Bean. So you should use one from spring-cloud.
Try to import org.springframework.cloud.client.discovery.DiscoveryClient instead of com.netflix.discovery.DiscoveryClient in your ClientService class.
Also you need to change this.disc.getInstancesById("a-bootiful-client") to this.disc.getInstances(...).
This would be because of 2 cases.
1: The first situation is whether the imported package does not match
If you used #EnableDiscoveryClient
import org.springframework.cloud.client.discovery.DiscoveryClient
"instead of "
com.netflix.discovery.DiscoveryClient
If you used #EnableEurekaClient use this below import
import org.springframework.cloud.netflix.eureka.EnableEurekaClient
2: I did not select the starer-web dependency when I created the module, have added this below dependency in pom.xml and rebuild the project to fetch the added dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Use com.netflix.discovery.EurekaClient instead of com.netflix.discovery.DiscoveryClient. This is the discovery client provided by Netflix.
If you want to use spring discovery client then use org.springframework.cloud.client.discovery.DiscoveryClient as suggested by #yongsung.yoon
I've also faced with the same issue, I solved it after adding spring boot-starter-web dependency

Disable table recreation in Spring Boot application

I'm trying to build a simple web application using Spring Boot. When I restart the application all database tables are recreated. I tried setting hibernate.hbm2ddl.auto to update or validate but that doesn't help.
This is my configuration:
#ComponentScan
#EnableAutoConfiguration
#EnableHypermediaSupport
#EnableSpringDataWebSupport
public class ApplicationConfig {
#Bean
public DataSource dataSource() {
DriverManagerDataSource datasource = new DriverManagerDataSource();
datasource.setDriverClassName("org.postgresql.Driver");
datasource.setUrl("jdbc:postgresql://localhost/mydatabase");
datasource.setUsername("myusername");
datasource.setPassword("mypassword");
return datasource;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("my.domain.package");
Properties jpaProperties = new Properties();
jpaProperties.setProperty("hibernate.hbm2ddl.auto", "update");
lef.setJpaProperties(jpaProperties);
return lef;
}
#Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
hibernateJpaVendorAdapter.setGenerateDdl(true);
hibernateJpaVendorAdapter.setDatabase(Database.POSTGRESQL);
return hibernateJpaVendorAdapter;
}
#Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
public static void main(String[] args) {
SpringApplication.run(ApplicationConfig.class, args);
}
}
Using --debug I get this (somewhat filtered):
2014-02-23 18:17:30.735 INFO 27716 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#66e43eb8: startup date [Sun Feb 23 18:17:30 CET 2014]; root of context hierarchy
2014-02-23 18:17:31.354 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'pageableResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=pageableResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=pageableResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]]
2014-02-23 18:17:31.355 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'sortResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=sortResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=sortResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]]
2014-02-23 18:17:31.726 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'viewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=thymeleafConfig; factoryMethodName=viewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [be/**************/******/ThymeleafConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=viewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2014-02-23 18:17:32.159 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'transactionManager': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=applicationConfig; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class **.**************.******.ApplicationConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]]
2014-02-23 18:17:32.160 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'entityManagerFactory': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=applicationConfig; factoryMethodName=entityManagerFactory; initMethodName=null; destroyMethodName=(inferred); defined in class **.**************.******.ApplicationConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; factoryMethodName=entityManagerFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]]
2014-02-23 18:17:32.160 INFO 27716 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'jpaVendorAdapter': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=applicationConfig; factoryMethodName=jpaVendorAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class **.**************.******.ApplicationConfig] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; factoryMethodName=jpaVendorAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]]
2014-02-23 18:17:33.031 INFO 27716 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerByCGLIB$$9ca466b9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-23 18:17:33.074 INFO 27716 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-23 18:17:33.092 INFO 27716 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-23 18:17:33.102 INFO 27716 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-23 18:17:33.779 INFO 27716 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2014-02-23 18:17:33.779 INFO 27716 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.42
2014-02-23 18:17:33.909 INFO 27716 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-02-23 18:17:33.909 INFO 27716 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3177 ms
2014-02-23 18:17:35.028 INFO 27716 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2014-02-23 18:17:35.028 INFO 27716 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2014-02-23 18:17:35.124 INFO 27716 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-02-23 18:17:35.385 INFO 27716 --- [ost-startStop-1] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: org.postgresql.Driver
2014-02-23 18:17:35.457 INFO 27716 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2014-02-23 18:17:35.592 INFO 27716 --- [ost-startStop-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
2014-02-23 18:17:35.622 INFO 27716 --- [ost-startStop-1] org.hibernate.Version : HHH000412: Hibernate Core {4.2.1.Final}
2014-02-23 18:17:35.627 INFO 27716 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000205: Loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=validate}
2014-02-23 18:17:35.628 INFO 27716 --- [ost-startStop-1] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2014-02-23 18:17:35.655 INFO 27716 --- [ost-startStop-1] org.hibernate.ejb.Ejb3Configuration : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2014-02-23 18:17:35.899 INFO 27716 --- [ost-startStop-1] o.h.s.j.c.i.ConnectionProviderInitiator : HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
2014-02-23 18:17:36.256 INFO 27716 --- [ost-startStop-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL82Dialect
2014-02-23 18:17:36.268 INFO 27716 --- [ost-startStop-1] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2014-02-23 18:17:36.284 INFO 27716 --- [ost-startStop-1] o.h.e.t.i.TransactionFactoryInitiator : HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
2014-02-23 18:17:36.292 INFO 27716 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2014-02-23 18:17:36.481 INFO 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
Hibernate: alter table project drop constraint FK_4725849e7c4543e3885bbd3a3a9
2014-02-23 18:17:36.488 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: alter table project drop constraint FK_4725849e7c4543e3885bbd3a3a9
2014-02-23 18:17:36.488 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : ERROR: constraint "fk_4725849e7c4543e3885bbd3a3a9" of relation "project" does not exist
Hibernate: alter table project drop constraint FK_56d354acd26e412daa99d5584ff
2014-02-23 18:17:36.489 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: alter table project drop constraint FK_56d354acd26e412daa99d5584ff
2014-02-23 18:17:36.489 ERROR 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : ERROR: constraint "fk_56d354acd26e412daa99d5584ff" of relation "project" does not exist
Hibernate: drop table if exists company cascade
Hibernate: drop table if exists project cascade
Hibernate: create table company (id serial not null, name varchar(255), primary key (id))
Hibernate: create table project (id serial not null, reference varchar(255), company int4, primary key (id))
Hibernate: alter table project add constraint FK_4725849e7c4543e3885bbd3a3a9 foreign key (company) references company
2014-02-23 18:17:36.577 INFO 27716 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
Your configuration isn't a #Configuration class.
Next to that I suggest that you use the power of Spring Boot. Which means I would suggest removing everything but the DataSource configuration and simply add an application.properties file with the following properties
spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
This should give you the desired behavior, with less coding.
You could even remove the datasource if you have either commons-dbcp or tomcat-pool in your classpath and adding the following properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/mydatabase
spring.datasource.username=myusername
spring.datasource.password=mypassword
If you are using spring boot, you could do it by configuration over the config file. Hibernate has all this possibilities:
validate (validate the schema)
update (update the schema if are changes)
create (create the schema)
create-drop (create the schema and drop it at the end)
but if you want don't do anything, spring boot add other chance, use as follow:
spring:
jpa:
hibernate:
ddl-auto: none
Your ApplicationConfig is not #Configuration. I imagine that means the Spring Boot autoconfig will also be applied. Can you try adding that?
If you are using a in-memory database then every time you start/stop spring boot application - it will recreate the whole thing unless you mention/configure spring boot to use the database from file system.
update your #Configuration or application.properties for below property
spring.datasource.url=jdbc:h2:file:/Users/user_name/database_file_name
Also check, you should not have spring.datasource.initialization-mode in config.

Resources