gpt4 book ai didi

java - 无法访问 org.springframework.web.WebApplicationInitializer

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:06:57 28 4
gpt4 key购买 nike

我目前正在研究使用 Spring 4、Java 1.8 和 Gradle (https://spring.io/guides/gs/scheduling-tasks/) 安排任务的示例。

但是,当运行这个例子时,我收到以下错误:

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 会导致此错误?

谢谢。

最佳答案

添加这个依赖来解决这个问题。我完美地为我工作。

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

关于java - 无法访问 org.springframework.web.WebApplicationInitializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41129553/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com