Getting "Error creating bean with name 'springSecurityFilterChain'" in Spring Boot - spring-boot

I got this error when I run the application. I tried to solve this problem by reading several posts but it makes no sense.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
and
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.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]

In the exception stack trace it seems not able to find the JAXB-API . Do you have this dependency to your project - jaxb-api.

Java 11 removed the Java EE modules: java.xml.bind (JAXB) - REMOVED
You can fix the issue by using alternate versions of the Java EE technologies. Simply add Maven dependencies that contain the classes you need:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
For Details Read This StackOverflow Answer

Related

ConfigClientOAuth2BoostrapConfiguration': Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: CLIENT_SECRET_BASIC

Upon running a security scan our service was detected with high vulnerability related to spring-security-oauth2-client(5.3.10.RELEASE).We tried following both the recommended fixes and tried upgrading it to version 5.6.9 or 5.7.5.But now our application is not starting and gives an error:
Error creating bean with name 'io.pivotal.spring.cloud.config.client.ConfigClientOAuth2BoostrapConfiguration': Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: CLIENT_SECRET_BASIC at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization
Versions we are using:
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-starter-config-client</artifactId>
<version>3.1.5.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.5.7</version>
</dependency>
I tried to play around with different dependency version but still its giving the same error

zipkin error Error creating bean with name 'webMvcMetricsFilter' defined in class path resource

When I tried to integrate zipkin. It threw this error
Error Msg:Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Initialization of bean failed;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkin2.server.internal.ZipkinServerConfiguration': Unsatisfied dependency expressed through field 'httpQuery';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zipkin2.server.internal.ZipkinQueryApiV2': Bean instantiation via constructor failed;
nested exception is java.lang.NoClassDefFoundError: zipkin2/internal/Buffer$Writer
version:
Springboot 2.2.4
SpringCloud Hoxton.SR1 (sleuth: 2.2.1)
zipkin 2.19.9
#EnableZipkinServer
#SpringBootApplication
public class C4ZipkinApplication {
public static void main(String[] args) {
SpringApplication.run(C4ZipkinApplication.class, args);
}
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-server</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
</dependency>
Your application starts in Tomcat Server but Zipkin use another server but i dont know that name , i include this code to spring boot starter web dependecy for ignore tomcat server
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
This worked for me try it
If you are using a config server, remember to run it before running your microservices.

Can I use Xfire with SpringBoot?

My application uses Xfire as a web service client, It a legacy system where service is written in Perl, I am modifying/rewriting application with Spring boot, when I add the Maven dependency, it shows error when I try to build
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-core</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-spring</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-aegis</artifactId>
<version>1.2.6</version>
</dependency>
[ERROR] contextLoads(com.au.cis.IPND.IpndApplicationTests) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType
Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
I don't know where database has been used
EmbeddedDatabaseType is part of spring-jdbc, so I would suggest adding the following dependency (if you do not already have it):
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.1.RELEASE</version>
</dependency>
Please do adjust the version number (5.2.1.RELEASE) to match your other Spring dependencies!

Spring Boot Elastic Search connection issue

Boot with Elastic Search using Spring Data JPA. To implement this, I created a sample Amazon account and launched sample Elasticsearch instance in the AWS console and got the details.
Now the problem is, the Spring BOOT Application is failing to due to connection issues to the AWS ElasticSearch. Not sure, I am adding the right dependencies.
AmazonElasticSearch Details :
https://search-elasticsearch-3wqyu7ekb7nymtxwosu7nxkbkq.us-east-2.es.amazonaws.com/
Pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
ElasticSearchConfiuration:
enter image description here
application.properties
elasticsearch.clustername = 008026978848:elasticsearch
elasticsearch.host = https://search-elasticsearch-3wqyu7ekb7nymtxwosu7nxkbkq.us-east-2.es.amazonaws.com/
elasticsearch.port = 9300
Exception Details
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/aws/elasticsearch/config/ElasticSearchConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.net.UnknownHostException: https://search-elasticsearch-3wqyu7ekb7nymtxwosu7nxkbkq.us-east-2.es.amazonaws.com/

Error while deploying Spring Batch Application - java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/MappedXMLOutputFactory

I am stuck with this error from last few days , while loading the spring batch application,it keep on giving error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository' defined in ServletContext resource [/WEB-INF/classes/spring/batch/jobs/config/context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/MappedXMLOutputFactory
I have added jettison to my pom and here below my pom file looks like
org.codehaus.jettison
jettison
1.3.2
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework.batch
spring-batch-test
${spring.batch.version}
jettison
org.codehaus.jettison
pom.xml should have dependency like :
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.2</version>
</dependency>
Also, do you see jettision-1.3.2.jar in your maven dependecies?
if you are using eclipse, ctr+sft+t : are you able to see this class?

Resources