Adam Sojka
Adam Sojka

Reputation: 391

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

Upvotes: 0

Views: 2646

Answers (1)

Adam Sojka
Adam Sojka

Reputation: 391

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.

Upvotes: 0

Related Questions