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

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.

Related

Tomcat 10, Java 17 - JavaMailSender cannot cast one of elements of java.lang.Object[]

After migrating application to Spring Boot 3 and Java 17 I tried to deploy it to Tomcat 10.1.x.
The deployment failed with exception:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mailSender' defined in class path
resource [org/springframework/boot/autoconfig
ure/mail/MailSenderPropertiesConfiguration.class]: Failed to
instantiate [org.springframework.mail.javamail.JavaMailSenderImpl]:
Factory method 'mailSender' threw exception with message: arraycopy:
element type mismatch: can not cast one of the elements of
java.lang.Object[] to the type of the destination array,
jakarta.activation.MimeTypeRegistry
The issue turned out to be caused by CXF library having dependency on:
com.sun.activation:jakarta.activation.
The solution is to exclude it from cxf:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<exclusions>
<exclusion>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
</exclusion>
</exclusions>
</dependency>
Instead include directly the jakarta.activation-api as below:
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.1</version>
</dependency>
There might be other libraries with the same dependency in the application.
For above the approach with deploying application to webapps-javaee folder and allowing Tomcat to perform migration doesn't work.

Getting the following error, any tips to resolving it? I am trying to convert from OAM to OKTA for authentication

I have a Spring application that I’ve been trying to switch over to Okta. I have not made it connect with OKTA yet. I am getting an error related to client registration.
I am using following dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<!-- <version>1.4.2.RELEASE</version>-->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<!--<version>1.5.2.RELEASE</version>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
Application.properties
spring.security.oauth2.client.provider.okta.issuer-uri=https://dev-327711.okta.com/oauth2/default
spring.security.oauth2.client.registration.okta.provider=okta
spring.security.oauth2.client.registration.okta.client-name=awards2
spring.security.oauth2.client.registration.okta.client-id=xxxx
spring.security.oauth2.client.registration.okta.client-secret=xxxx
spring.security.oauth2.client.registration.okta.redirect-uri=/authorization-code/callback
spring.security.oauth2.client.registration.okta.scope=openid,profile,email
Error trace:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration':
Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration':
Unsatisfied dependency expressed through method 'setClientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]: Factory method 'clientRegistrationRepository' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.oauth2.client.registration.ClientRegistration.withRegistrationId(Ljava/lang/String;)Lorg/springframework/security/oauth2/client/registration/ClientRegistration$Builder;
After reading OAuth2 document I resolved this issue by adding "autoconfigure" dependency.
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.4.5</version>
</dependency>
https://docs.spring.io/spring-security-oauth2-boot/docs/2.0.0.RC2/reference/htmlsingle/

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/

Getting "Error creating bean with name 'springSecurityFilterChain'" in 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

Error creating bean with name 'org.springframework.security.saml.SAMLBootstrap#0'

I am adding SSO code in the webpage using SAML. And for this process I added the following code for Maven.
<!-- Spring Framework Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- Spring Security SAML -->
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
And I added the following code in the application context xml.
<!-- Initialization of OpenSAML library -->
<bean class="org.springframework.security.saml.SAMLBootstrap" />
But I get the following error
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.saml.SAMLBootstrap#0' defined in class
path resource [conf/spring/root-context.xml]: Instantiation of bean
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.springframework.security.saml.SAMLBootstrap]: No
default constructor found; nested exception is
java.lang.NoClassDefFoundError:
org/springframework/beans/factory/access/BootstrapException
It appears certain jars are missing. How do I add this jar?
Thanks
Jae Kim
Bottom line is: update to 1.0.3.RELEASE solves the problem.
Explanation: class SAMLBootstrap throws (line 45) BootstrapException, which exists in spring-4 (spring-beans-4.2.4.RELEASE) but not in spring-5.
In spring-security-saml2-core-1.0.3.RELEASE the dependency in class BootstrapException is removed.
According to this issue https://github.com/spring-projects/spring-security-saml/issues/211
You just have to update saml library to the latest version
1.0.4.RELEASE

Resources