我目前正在通過使用Spring 4,Java 1.8和Gradle(https://spring.io/guides/gs/scheduling-tasks/)計劃任務的示例。無法訪問org.springframework.web.WebApplicationInitializer
然而,運行這個例子的時候,我收到以下錯誤:
Error:(11, 8) java: cannot access org.springframework.web.WebApplicationInitializer class file for org.springframework.web.WebApplicationInitializer not found
的源代碼,以我的Application.java如下:
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);
}
}
我gradle這個文件:
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'
}
爲什麼org.springframework.web.WebApplicationInitializer在甚至連男人都不會造成這個錯誤在指南中?
謝謝。
你可以發佈你的gradle文件嗎 –
@KlausGroenbaek當然,我已經添加到我原來的帖子了。謝謝。 – 000000000000000000000