0

I have a Spring project from a while ago. It runs perfectly on my old server. However, on a more modern server, I can't seem to get it to run. This is what I get when I run mvn spring-boot:run:

 path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$
EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverProperties' defined in class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException: javax.xml.bind.ValidationException ->

I'm using Maven, and here is the pom.xml dependencies

<parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.3.5.RELEASE</version>
        </parent>

        <dependencies>
        <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
    <optional>true</optional>
</dependency>
                <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.6</version>
    <optional>true</optional>
</dependency>
<dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
        <optional>true</optional>
</dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
      <optional>true</optional>
                </dependency>

                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.11</version>
      <optional>true</optional>
                </dependency>

        </dependencies>

It's a large pom.xml but somewhat redundant.

lee
  • 740
  • 2
  • 11
  • 24
  • What version of JDK do you use to compile this project? – Ishikawa Yoshi Jan 27 '21 at 19:45
  • @IshikawaYoshi `OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.10)` – lee Jan 27 '21 at 19:47
  • 1
    Could you please check this answer https://stackoverflow.com/a/43574427/1063509 i suppose it related to your problem. java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException: javax.xml.bind.ValidationException – Ishikawa Yoshi Jan 27 '21 at 19:48
  • as far as i remember Java 11 is supported from Spring Boot 2.1.0 here is also usefull link https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-Java-9-and-above#jaxb – Ishikawa Yoshi Jan 27 '21 at 19:55

1 Answers1

1

JDK 9 and beyond has removed some XML packages from the JDK. Most probably your old server was running on a JDK 8, which included these packages. You need to add them as dependencies now as you are running your application on JDK 11. Adding this to your dependencies should fix it:

<!-- API, java.xml.bind module -->
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.2</version>
</dependency>

<!-- Runtime, com.sun.xml.bind module -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>
Simulant
  • 19,190
  • 8
  • 63
  • 98