Springboot client server architecture - spring-boot

Created Eureka discovery client and server architecture. In client there is userInfo service CRUD opeartion. Its showing error while starting . Error is Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#2626b418].

This looks like an issue with the Spring boot version and Spring Cloud version. As per the reference Deprecated ConfigurationBeanFactoryMetadata is removed in Spring Boot 2.3.0.M1, the reported class is deprecated.
Please choose the correct version of Spring Boot and Spring Cloud to continue, refer to Release train Spring Boot compatibility
Pasting my pom.xml version for reference, hope it helps:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>15</java.version>
<spring-cloud.version>2020.0.1</spring-cloud.version>
</properties>

Related

Spring-boot Issue in retrieving AWS-Parameter store values which are configured in application.yaml

I am migrating an spring-boot application from 2.2.6 to 2.6.6 due to recent RCE issue.
My application is hosted in AWS. I have application.yaml, where we configured few values to retrieve from AWS Parameter store like datasourceUrl, dbUserName etc.
Binding between these values from yaml file and parameterstore is happening correctly in 2.2.6.
But, having issue when I migrated to 2.6.6.Below is the error am getting when ECS service is starting:
Not sure what I am missing in this migration.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, **${datasourceUrl}**
Below are updated dependencies I have added as part of this migration.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/>
</parent>
<!-- Cloud dependencies version used-->
<spring-cloud.version>2021.0.1</spring-cloud.version>
<!-- AWS Parameter store versions used-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-parameter-store-config</artifactId>
<version>2.4.1</version>
</dependency>

Spring Cloud Config Client not working with spring boot 2.5.1

Spring cloud config client not working with Spring Boot 2.5.1 but working with 2.5.0.
application-dev.yml
spring:
config:
import: configserver:http://localhost:8270/
cloud:
config:
enabled: true
Error
***************************
APPLICATION FAILED TO START
***************************
Description:
Config data location 'configserver:http://localhost:8270/' does not exist
Action:
Check that the value 'configserver:http://localhost:8270/' at class path resource [application-dev.yml] - 3:13 is correct, or prefix it with 'optional:'
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
...
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
...
I am running Spring Cloud Config Server with Spring boot 2.4.4 and Spring Cloud version 2020.0.1
This is due to a regression in Spring Boot 2.4.7 and 2.5.1. The regression means that the import will not work when it’s declared in a profile-specific file. Until it has been fixed you could stay on an earlier version of Boot or temporarily move the import to application.yml.

Do Spring LDAP and Spring Cloud Consul work together?

I had a project with Spring LDAP in place. I am trying to put in Spring Consul into this project and have been facing issues with respect to it.
Here is the pom.xml :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
Here is application properties :
#consul properties
spring.cloud.consul.config.format=PROPERTIES
spring.cloud.consul.discovery.healthCheckPath=/<root>/health
spring.cloud.consul.discovery.healthCheckInterval=15s
spring.application.name=<App_Name>
spring.profiles.active=dev
And I enabled discovery client using #EnableDiscoveryClient on SpringBootApplication class.
But, I am ending up with this error and the app never starts :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field ldapTemplate in com.<package>.config.LdapClient required a bean of type 'org.springframework.ldap.core.LdapTemplate' that could not be found.
- Bean method 'ldapTemplate' not loaded because #ConditionalOnClass did not find required class 'org.springframework.data.ldap.repository.LdapRepository'
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.ldap.core.LdapTemplate' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:62703', transport: 'socket'
I figure it has something to do with autodiscovery of Ldap and introducing Consul is causing this issue, but, I am not able to pin-point the problem.
Can someone please help me resolve this issue?

Testing Neo4j with Spring Boot and embedded driver

Problem
I build an application using a Neo4j database. I like to test some custom Cypher queries using Spring Boot's #DataNeo4jTest annotation (see also Spring Boot Test - Neo4j), but I run in either one of the following problems:
The test tries to connect to a Neo4j instance using the BOLT driver.
The test fails to load the embedded driver.
Details
My dependencies are managed with Maven following the Spring Data Neo4j Reference Documentation. Section 10.3.1 of the SDN documentation explains:
By default, SDN will use the BOLT driver to connect to Neo4j and you don’t need to declare it as a separate dependency in your pom. If you want to use the embedded or HTTP drivers in your production application, you must add the following dependencies as well. (This dependency on the embedded driver is not required if you only want to use the embedded driver for testing. See the section on Testing below for more information).
Therefore, the relevant parts of my pom.xml are:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi=...>
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
...
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>3.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
...
</project>
My main/resources/application.yml is:
spring:
data:
neo4j:
uri: bolt://localhost
username: <username>
password: <password>
My test/resources/application.yml is:
spring.data.neo4j.uri: file:///neo4j.db
Without the test/resources/application.yml I get the following exception, which I assume is caused by using the BOLT driver:
org.springframework.transaction.CannotCreateTransactionException: Could not open Neo4j Session for transaction;
nested exception is org.neo4j.driver.v1.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
With the test/resources/application.yml I get the following exception:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'neo4jAuditionBeanFactoryPostProcessor': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception;
nested exception is org.neo4j.ogm.exception.core.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
Questions
Are there any dependencies missing?
Is the configuration wrong?
Does anyone have a link to a working example using the Spring Boot annotation #DataNeo4jTest?
Any suggestion is welcome.
I have found a solution to my problem. It seems as if the BOLT driver is used as default for testing as well - which is confusing given the Spring Data Neo4j (SDN) documentation. Finally, the pom.xml of the GitHub project movies-java-spring-data-neo4j helped me. I added the following test dependency to my pom.xml:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>${neo4j-ogm.version}</version>
<scope>test</scope>
</dependency>
I kept the test/resources/application.yml but removed the line:
spring.data.neo4j.uri: file:///neo4j.db
Now, the test context starts with the embedded driver, and creates a temporary database file like file:/C:/Users/Me/AppData/Local/Temp/neo4j.db6943517458205762238/, which is awesome. I can get a clean database instance for every test method.
I hope this answer will help others, who have the same problem. I'm happy to provide more details if necessary.
#DataNeo4JTest works great with Spring Boot 2.x.
Example Test:
#RunWith(SpringRunner.class)
#DataNeo4jTest
public class WidgetRepositoryTest {
#Autowired
private WidgetRepository repository;
private Widget widget;
#Before
public void setUp() {
widget = WidgetTestData.builder().build();
}
#Test
public void itShouldSaveAndRetrieve() {
final Widget saved = repository.save(widget);
assertThat(saved.getId()).isNotNull();
assertThat(saved.getName()).isEqualTo(widget.getName());
final Optional<Widget> found = repository.findById(saved.getId());
assertThat(found).hasValueSatisfying(w-> {
assertThat(w.getId()).isEqualTo(saved.getId());
assertThat(w.getName()).isEqualTo(saved.getName());
});
}
}
The Neo4J-related dependencies in my Maven POM:
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>

Spring boot sample: Unable to start embedded container error

I am new to spring, so i downloaded jar from spring intializr for maven-web java 1.8 demo. I extracted and imported it to STS to run the main() file and I get below exception. Can some one tell me what's solution for this?
Solutions I tried from web but didn't work:
- Tried adding Hibernate-validator dependency to pom
- Tried adding spring-boot-starter-tomcat dependency to pom
STACK TRACE:
2017-01-26 12:19:32.587 INFO 3816 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2e4b8173: startup date [Thu Jan 26 12:19:32 EST 2017]; root of context hierarchy
2017-01-26 12:19:36.442 WARN 3816 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2017-01-26 12:19:36.454 ERROR 3816 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath
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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.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>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application file:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Had the same problem with release version 1.5.9 of Spring Boot.
To add to the answer by Jim Kiley, you should add the following in Maven pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.6.Final</version>
</dependency>
You can use the dependency version under properties section of Spring Boot pom.xml file (spring-boot-dependencies-1.5.9.RELEASE.pom):
<hibernate-validator.version>5.3.6.Final</hibernate-validator.version>
Located under path:
/.m2/repository/org/springframework/boot/spring-boot-dependencies/1.5.9.RELEASE/spring-boot-dependencies-1.5.9.RELEASE.pom
As the output says, you need to:
Add an implementation, such as Hibernate Validator, to the classpath
Since you're using Maven, that means you need to add the Hibernate Validator to your pom.xml's dependencies.
First of all, your pom.xml settings are correct.
spring-boot-starter-web has the dependency to hibernate-validator.
So in your project, you don't need to specify the dependency to hibernate-validator. Otherwise, what's the purpose to use maven?
So back to the resolution, the steps I did to resolve the problem are:
Goto project folder where the pom.xml is located.
Run mvn verify
The command will download the missing jar again from the repository and also check the correctness(corrupted or not) of jars in maven local repository.
If you see the warning messages similar to following:
[WARNING] error reading /home/vagrant/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.6/tomcat-embed-core-8.5.6.jar; invalid LOC header (bad signature)
[WARNING] error reading /home/vagrant/.m2/repository/org/hibernate/hibernate-validator/5.2.4.Final/hibernate-validator-5.2.4.Final.jar; invalid LOC header (bad signature)
[WARNING] error reading /home/vagrant/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.4/jackson-core-2.8.4.jar; invalid LOC header (bad signature)
Then this means that the jars downloaded by maven previously has been corrupted.
To correct this, please delete those corrupted jars and run mvn verify again to re-download them and also ensure that there's no warning for jars.
Go back to your IDE(STS or Eclipse), update your project and run the application again.
In above error the hibernate-validator-5.2.4.Final.jar is the hibernate validator that in quesion.
I met same issue and resolved it by delete these two folders under .m2
com\fasterxml --> delete it will resolve TypeResovler issue.
org\springframework --> delete it will resolve lack of validator
issue.
then the program works.
I faced the same issue while runs the application and resolved the issue by deleting the .m2 folder.
.m2/repository

Resources