导入org.springframework无法解析 [英] Import org.springframework cannot be resolved

查看:1155
本文介绍了导入org.springframework无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spring DI创建一个简单的HelloWorld应用程序。我创建了一个Java项目并导入了一些教程类,其中一个很简单:

I'm trying to create a simple HelloWorld application with Spring DI. I created a Java project and imported some tutorial classes, one of which is simple this:

package helloworld;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;

import java.io.FileInputStream;
import java.util.Properties;

public class HelloWorldSpring {

    public static void main(String[] args) throws Exception {

        // get the bean factory
        BeanFactory factory = getBeanFactory();

但是我收到以下错误:导入org.springframework不能解决
我正在使用Eclipse Spring Tool Suite 3.7.2,我认为通过使用这个Eclipse版本,当我点击修复项目设置时,它会为我添加这些依赖项。我在这做错了什么?即使在STS中,我是否需要手动添加这些依赖项?如果是,那么正确的方法是什么?

However I'm getting the following error: The import org.springframework cannot be resolved. I'm using Eclipse Spring Tool Suite 3.7.2, and I thought that by using this Eclipse version when I clicked "Fix project setup", it would add these dependencies for me. What am I doing wrong here? Do I need to add these dependencies manually even in STS? If yes, what's the correct way to do it?

推荐答案

如果您使用的是maven,则需要将其添加到您的pom中。 xml

If you are using maven you need to add this to your pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.4.RELEASE</version>
    </dependency>
</dependencies>

这篇关于导入org.springframework无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆