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
Related
I have developed a small REST API application with Spring Boot after another sample application with classic Spring XML configuration. It imports context from a library with a Coherence cache set up.
When I developed it locally, running the Spring Boot app with Intellij Idea runner, there were no issues, the application worked fine and the endpoint worked connecting to that cache.
When I deployed the application to the Unix server, I am getting the following error during the application startup:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coreSearchSync' defined in class path resource [core-search-core-context.xml]: Cannot resolve reference to bean 'corePersistenceManager' while setting bean property 'corePersistenceManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'corePersistenceManager': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' coreSearchResultCache' defined in class path resource [core-search-coherence-context.xml]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.tangosol.net.NamedCache]: Factory method 'getCache' threw exception; nested exception is (Wrapped: Failed to start Service "Management" (ServiceState=SERVICE_STOPPED)) java.lang.RuntimeException: Join request was aborted
The application on the server is using the application.properties but they are the same as in the application.yaml locally.
I am not sure where to continue the investigation...
The problem was solved by passing JVM arguments to the script to start the application:
-Dtangosol.coherence.clusterport=<port> -Dtangosol.coherence.site=<site> -Dtangosol.coherence.clusteraddress=<cluster_ip_ddress> -Dtangosol.coherence.cluster=<cluster_name>
It appears that these properties are not applied from the application properties because starting the coherence cluster works on the system level and/or starts before the properties are initialized. Or those properties are not visible to the coherence.
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'countryServiceImpl' defined in file [E:\tms-ws\TransportManagement\target\classes\com\baltransport\tms\app\v1\service\impl\CountryServiceImpl.class]:
Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'countrySearchRepository': Invocation of init method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.data.elasticsearch.repository.support.NumberKeyedRepository]:
Constructor threw exception; nested exception is org.springframework.data.elasticsearch.ElasticsearchException: Failed to build mapping for country:country
at org.springframework. ...
Getting this exception jHispter Elasticsearch issue after adding any custom entity .
It works perfectly fine first time (with default jdl)
U can try:
Delete db and create again.
Import your jdl, with the news changes, maybe new entity.
Run elasticsearch in docker. (Find this file .yml in your project) and check if this is run correctly (localhost:9200)
Run your app (monolith or microservices)
Regards
you can try to delete the indexes in elasticsearch directly from the url.
Supposing you index is called "user" you can do the
DELETE /indexname
I configured two data sources in my app following the guide of spring example:https://github.com/spring-cloud/spring-cloud-task/blob/master/spring-cloud-task-samples/multiple-datasources.
The spring boot version I use is :2.0.0.RELEASE
The spring.cloud.task.version I use is :1.2.2.RELEASE.
This application works fine in my local computer, But when deploy to the to AWS, I got the following error with the defination of class:CustomTaskConfigurer.java.
which defined the same as here:https://github.com/spring-cloud/spring-cloud-task/blob/master/spring-cloud-task-samples/multiple-datasources/src/main/java/io/spring/configuration/CustomTaskConfigurer.java
The error message is like below:
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.task.configuration.SimpleTaskConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customTaskConfigurer' defined in file [/home/vcap/app/BOOT-INF/classes/com/xxx/configuration/CustomTaskConfigurer.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.configuration.CustomTaskConfigurer$$EnhancerBySpringCGLIB$$bc80cd46]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Unable to create a TaskExecutionDao.
The root cause for this error is that when I developed the application locally I configure a local datasource bean for postgresql like below:
#Bean
#Primary
#ConfigurationProperties("spring.datasource")
public HikariDataSource sourceDataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
This bean read the properties in the application.properties file which identify the username and password url for the local postgres.
When This application deloyed to cloud,It will connect to the cloud data base instead of the local databases, which means the url,username,and password are no longer correct.
After add the configuration for cloud, this error disppeared.
But this exception stack trace only tell you that it is unable to create taskExecutionDao, It is really hard for the user to fix the issue when see such a error message
If it is a multiple datasource issue, you can try marking it as #Primary. Providing a better stack trace is helpful.
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
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/