1

I am doing Spring boot mvc project with JSP. When I use version 2.0.0.RELEASE, everything is ok! Here is part of my pom.xml:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        ...

And this is my startup class:

package com.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class TestApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TestApplication .class);
    }

    public static void main(String[] args) {
        SpringApplication.run(TestApplication .class, args);
    }
}

But when I change my spring-boot-starter-parent to 2.2.1.RELEASE Eclipse report error in my startup class:

Multiple markers at this line
    - The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from 
     required .class files
    - The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from 
     required .class files

I know that I can add some other dependencies to solve this, but I don't want to. Could anybody guide me to the difference in spring boot versions? Thanks in advance!

Magic
  • 149
  • 1
  • 1
  • 12
  • Spring Boot 2.2 switched to the Jakarta variant of the Servlet API. I would guess that Maven has corrupted its jar file when it downloaded it. Try clearing Maven’s cache and building your application again. – Andy Wilkinson Dec 15 '19 at 14:14
  • I did project clean and Maven clean many times but no help. I can't find javax.servlet dependencies from Eclipse pom viewer no matter I use starter-parent 2.0.0 or 2.2.1. I have no clue why 2.0.0 is OK but 2.2.1 report errors. – Magic Dec 17 '19 at 08:14
  • A `clean` won’t clear Maven’s cache. Please see [this question](https://stackoverflow.com/questions/7408545/how-do-you-clear-apache-mavens-cache#7409208) for how to do it. – Andy Wilkinson Dec 17 '19 at 09:02
  • Delete my whole local repository will cause many re-download. Is there any way to identify the one which causes the problem then I can delete it only? (My Eclipse sometimes fails to download the dependencies and cause problems. I always delete the specific library/version and edit pom to trigger a re-download until it success) – Magic Dec 24 '19 at 04:30
  • mvn dependency:purge-local-repository solved my issue. Thanks, Andy! – Magic Dec 26 '19 at 02:13

0 Answers0