cannot access org.springframework.web.WebApplicationInitializer

13,876

Solution 1

Add this dependency to fix this problem. I perfectly worked for me.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency> 

Solution 2

The guide does not extend SpringBootServletInitializer, remove it or add spring-boot-starter-web as a dependency if you want to start a Tomcat webserver inside you application.

Share:
13,876

Related videos on Youtube

000000000000000000000
Author by

000000000000000000000

Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun! Coding is fun!

Updated on September 15, 2022

Comments

  • 000000000000000000000
    000000000000000000000 about 1 year

    I am currently working through the example on scheduling tasks using Spring 4, Java 1.8, and Gradle (https://spring.io/guides/gs/scheduling-tasks/).

    However, when running this example, I receive the following error:

    Error:(11, 8) java: cannot access org.springframework.web.WebApplicationInitializer class file for org.springframework.web.WebApplicationInitializer not found

    The source code to my Application.java is as follows:

    package hello;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.support.SpringBootServletInitializer;
    import org.springframework.scheduling.annotation.EnableScheduling;
    
    @SpringBootApplication
    @EnableScheduling
    public class Application extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class);
        }
    }
    

    My gradle file:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'war'
    
    jar {
        baseName = 'gs-scheduling-tasks'
        version =  '0.1.0'
    }
    
    repositories {
        mavenCentral()
    }
    
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    dependencies {
        compile("org.springframework.boot:spring-boot-starter")
        testCompile("org.springframework.boot:spring-boot-starter-test")
        providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    }
    

    Why is org.springframework.web.WebApplicationInitializer causing this error when it is not even mentioned in the guide?

    Thanks.