java - Spring 应用程序的问题,基于 spring.io 教程

标签 java spring eclipse gradle

我正在尝试学习 Spring 框架,因此我决定遵循 Spring.io 网站上提供的教程。我的应用程序中的章节存在问题:http://spring.io/guides/gs/rest-service/

我前一天和 friend 一起做的,应用程序可以工作并且仍在工作。我尝试自己做,但在主类中我收到错误:

错误堆栈跟踪

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
    The method run(Object, String...) from the type SpringApplication refers to the missing type ConfigurableApplicationContext 

我现在正在公司办公室尝试这样做,难道是我公司宽带的安全软件有问题吗?

主类:Application.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

最佳答案

我认为这与您的类路径有关,该路径没有所需的类文件。我建议您在没有任何IDE的情况下独立构建项目来检查所有依赖项解析并确保工作正常。为此,只需在环境变量上设置 JAVA_HOMEMAVEN_HOME (假设您使用的构建工具是 MAVEN),并使用命令(mvn cleancompile package install)在没有任何 IDE(Netbeans 或 Eclipse)的情况下构建您的项目,它将解决所有与依赖项相关的问题,并从中央存储库下载所需的 jar,成功构建后,将在项目的目标目录中创建 jar。

如果您使用任何 IDE,请确保类路径上的所有依赖项均可用。

在您的情况下,所需的 jar 是 spring-boot-starter-web 来解决 ConfigurableApplicationContext 的问题。

关于java - Spring 应用程序的问题,基于 spring.io 教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45484925/

相关文章:

java - 当指定一周的第一天时,查找特定日期的星期几

java - Spring表达式语言: @Bean cannot find itself

java - 如何将CustomDateEditor绑定(bind)到Springframework中的所有日期字段?

java - 我如何续订 Spring session ?

java - log4j 的默认日志文件转储路径是什么

java - 从 Eclipse 提交代码到 svn 时出现异常

java - 录制的视频失真(FFMPEG)

java - 当前月份的开始和结束日期

Java - 在 Android 应用程序上打印非拉丁字符

linux - 从 Eclipse Luna 中删除 Gnome 样式