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

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.

Related

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.

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

ClassNotFoundException: DirectoryService with apacheds-all already included

I am implemented LDAP authentication in my Spring Boot Application. The dependencies added are as follows:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
</dependency>
However I am still getting following ClassNotFoundException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]
Caused by: java.lang.NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
Caused by: java.lang.ClassNotFoundException: org.apache.directory.server.core.DirectoryService
My maven dependency tree clearly shows apacheds-all is added successfully.
Why am I still getting this error?
Spring Security doesn't support Apache DS 2.0. Instead, you need to use 1.5.5. Also, note that later 1.5.x versions are not supported due to breaking API changes.

Exception occurred while accessing jsf page: Servlet.service() for servlet default threw exception: java.lang.NoSuchMethodError

I'm trying to develop a web application using following technologies JSF 2.0 , EJB 3, JPA, Maven.. It's based on MVC design pattern so I have 3 projects so far: one is an EJB project which contains business and model, the second one is the view part which contains JSF and all beans that will be used in JSF pages and the third one is an EAR projects used to unite previous project that I mentioned.
So far I made a simple app and the EAR Project was deployed successfully in JBoss 7 but whenever I try to access a page I get the following exception:
Servlet.service() for servlet default threw exception: java.lang.NoSuchMethodError: com.ocpsoft.pretty.PrettyContext.newDetachedInstance(Ljavax/servlet/http/HttpServletRequest;)Lcom/ocpsoft/pretty/PrettyContext;
I want to mention that I'm not so familiar with these technologies.
Please let me know if you want to give you additional info such as maven dependencies or whatever you think that it can cause this error.
I have the following dependencies related to prettyfaces:
<dependency>
<groupId>com.ocpsoft</groupId>
<artifactId>ocpsoft-pretty-faces</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>2.0.11.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-integration-faces-annotations</artifactId>
<version>2.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>2.0.11.Final</version>
</dependency>
I guess that the prettyfaces-core is missing, try to add this dependency :
<dependency>
<groupId>com.ocpsoft</groupId>
<artifactId>prettyfaces-core</artifactId>
<version>3.0.0</version>
</dependency>
I'm not sure about it, if it doesn't work, try the depedencies listed in the link below
http://mavenhub.com/c/com/ocpsoft/pretty/prettycontext

Resources