Unable to run my springboot web application - spring-boot

I have an spring cloud based project. When I run my application it shows the following error:
Error creating bean with name 'swaggerConfiguration' defined in class path resource [com/humatics/base/commons/swagger/autoconfigure/SwaggerAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [io.swagger.jaxrs.config.BeanConfig]: Factory method 'swaggerConfiguration' threw exception; nested exception is java.lang.NoSuchMethodError:
com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;

Related

Error creating bean with name 'springSecurityFilterChain' defined in class path

Hoping are well.
I'm not using web.xml for my spring configuration, and when running my repository tests after migrating to JHipster I'm getting this error:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'springSecurityFilterChain' defined in
class path resource
[org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [javax.servlet.Filter]: Factory method
'springSecurityFilterChain' threw exception; nested exception is
java.lang.IllegalStateException: Cannot apply
org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer#7744f9fa
to already built object
Is there any recommendation?

Spring Boot: How to define new object classes in UnboundID LDAP?

In a Spring Boot 2.1.6 project I'm using the embedded LDAP service (UnboundID LDAP). I need to define new attribute types and object classes. My LDIF file contains something like that:
dn: cn=schema
changetype: modify
add: attributetypes
attributetypes: ( 2.25.128424792425578037463837247958458780603.1 NAME 'customAttribute' DESC 'a custom attribute' EQUALITY caseIgnoreMatch SYNTAX '1.3.6.1.4.1.1466.115.121.1.15' )
However, when I deploy my WAR on tomcat I get this exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'directoryServer' defined in class path resource [org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.unboundid.ldap.listener.InMemoryDirectoryServer]: Factory method 'directoryServer' threw exception; nested exception is java.lang.IllegalStateException: Unable to load LDIF classpath:test.ldif
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.unboundid.ldap.listener.InMemoryDirectoryServer]: Factory method 'directoryServer' threw exception; nested exception is java.lang.IllegalStateException: Unable to load LDIF classpath:test.ldif
...
Caused by: LDAPException(resultCode=68 (entry already exists), errorMessage='Unable to add an entry with a DN that is the same as or subordinate to the subschema subentry DN 'cn=schema'.', ldapSDKVersion=4.0.11, revision=34e39aab27ea4fb92659a6888933db08099c7e41)
at com.unboundid.ldap.listener.InMemoryRequestHandler.addEntry(InMemoryRequestHandler.java:4916)
at com.unboundid.ldap.listener.InMemoryRequestHandler.importFromLDIF(InMemoryRequestHandler.java:4624)
at com.unboundid.ldap.listener.InMemoryDirectoryServer.importFromLDIF(InMemoryDirectoryServer.java:1255)
at org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration.importLdif(EmbeddedLdapAutoConfiguration.java:164)
... 76 more
What happens obviously is that, for some reason, the LDAP service "thinks" that I'm trying to ad the entry "cn=schema", and refuses the operation as the entry already exists, while I'm trying to modify it, hence the statememnt "changetype: modify" in the LDIF file.
Could someone please advise me what I'm doing wrong ?
Many thanks in advance.
Kind regards,
Nicolas

Spring Boot + HikariCP - non-deterministic failure to auto-configure a DataSource

On my local machine, when I run one of my Spring Boot 2.0.0 applications from IntelliJ, the application periodically fails to start and the following message is displayed in the console:
Application Failed to Start
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable drive class
When I get this error, if I try to run the application again it will (sometimes) start. The behavior seems non-deterministic. Sometimes the application starts on the first try, sometimes it takes a few consecutive attempts.
Edit ----------------------------------------------------------------------------
The error appears to be caused by the application failing to determine what profile is active. When the application fails to start, the Spring logging output states "No active profile set, falling back to default profiles: default". When the application starts successfully, the logging output states "The following profiles are active: local,permitall", which are the profiles I set to active in application.properties.
Unfortunately, whether or not Spring determines what profile is active when starting is a roll of the dice for me.
----------------------------------------------------------------------------------
My application is configured to use spring-boot-starter-data-jpa and connect to a Postgres database. For connection pooling I use HikariCP 2.7.8.
The console error (see below) implies that Hikari is failing to load a data source. Since this error is non-deterministic, maybe it depends on the order that Spring creates beans during startup?
The spring.datasource.url property is defined in my local application properties file. The application properties file sets the spring active profile property to local.
This is my application.properties file
spring.profiles.active=local,permitall
management.endpoints.web.base-path=/
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
This is my application-local.properties
spring.datasource.url=jdbc:postgresql://localhost/vms?currentSchema=vms
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
I haven't found a pattern to the failures or the successes. Any ideas on solving or troubleshooting this problem are appreciated.
Console error message
2018-05-18 13:53:49.667 ERROR 16228 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource
[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$61a24aeb]: Constructor threw exception;
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$Hikari.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

Springboot datasource exception

when i put jpaDependencency compile('org.springframework.boot:spring-boot-starter-data-jpa')
i am getting this Exception
2018-02-28 13:18:20.062 WARN 15208 --- [ 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 (no profiles are
currently active).
You need to add a Database driver JAR. If you include an embedded one, Spring Boot will pick and configure it by default.
You can add:
compile("com.h2database:h2")
Check out this getting started guide: https://spring.io/guides/gs/accessing-data-jpa/

Spring Boot application WAR deployment to Resin 4: is there a way to use app (WEB-INF/lib) classloader first?

I'm trying to deploy Spring Boot app as a WAR to Caucho Resin 4. I'm getting an error on hitting the app:
org.springframework.context.ApplicationContextException: Unable to
start embedded container; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name
'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration'
: Bean instantiation via constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$
$EnhancerBySpringCGLIB$$58b91c9d]: Constructor threw exception; nested
exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error
creating bean with name 'dashboardResource' defined in file
[/var/resin/webapps/itasng-0.8.5/WEB-INF/classes/gov/nih/cit/itasng/
rest/DashboardResource.class]: Unsatisfied dependency expressed through
constructor parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error
creating bean with name 'payPeriodRepository' defined in file
[/var/resin/webapps/itasng-0.8.5/WEB-INF/classes/gov/nih/cit/itasng/
persistence/PayPeriodRepository.class]: Unsatisfied dependency
expressed through constructor parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name
'org.springframework.orm.jpa.SharedEntityManagerCreator#0': Cannot
resolve reference to bean 'entityManagerFactory' while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'entityManagerFactory' defined in class path resource
[org/springframework/boot/autoconfigure/orm/jpa/
HibernateJpaAutoConfiguration.class]: Invocation of init method failed;
nested exception is java.lang.NoSuchMethodError:
javax.persistence.Table.indexes()[Ljavax/persistence/Index; at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
.onRefresh(EmbeddedWebApplicationContext.java:137)
~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
...
It's obvious that this is a typical class-loading issue: classes loaded by the parent class-loader from Resin lib (e.g. lib/javaee-16.jar) cause issues for the app built with newer versions (e.g. WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar).
Most app servers that I used before have a setting somewhere in a vendor specific –web.xml descriptor to switch the classloader order so that WEB-INF/lib classes load first. However, the Resin docs don't really have an easy answer if such an option exists.
Is there a way to switch class loading order in Resin 4 or what would be an alternative solution?
In Resin 4.0 there is no way to use app classloader first.
Potential workarounds for related classloading issues could involve using
the <jvm-classpath> which has precedence over Resin's classpath.
An example use case is to use later versions of JPA instead of JPA 2.0, which is deployed out-of-the-box.
Documentation reference:
http://www.caucho.com/resin-4.0/admin/cluster-config.xtp#jvm-classpath

Resources