【问题标题】:BeanException is not correctly resolved in Idea IDEIdea IDE 中未正确解决 BeanException
【发布时间】:2013-08-30 05:56:41
【问题描述】:

代码:

import org.springframework.beans.BeansException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Hello {
    private String s;

    public Hello(String str){
        s = str;
    }

    public void sayHi(){
        System.out.println(s);
    }

    public static void main(String []args){
        ClassPathXmlApplicationContext ac = null;//
        try {
            ac = new ClassPathXmlApplicationContext(new String[] {"config.xml"});
            Hello h = (Hello) ac.getBean("hello");//
            h.sayHi();
        } catch (BeansException e) {
            e.printStackTrace();  
        }
    }
}

IntelliJ Idea 标记为红色的问题:

这很奇怪,因为 BeansException 从 Throwable 继承: http://static.springsource.org/spring/docs/2.0.2/api/org/springframework/beans/BeansException.html 什么原因以及如何解决?

【问题讨论】:

  • 如果你构建你的项目会发生什么?
  • 谢谢。这是个好问题。我已经安装了 maven 并进行了全新安装,一切都很好。看来问题只有IntelliJidea IDE了。
  • 我发表了我的评论作为答案,因为它解决了您的问题。

标签: java spring intellij-idea


【解决方案1】:

尝试重建项目。该代码是有效的,应该可以编译。您使用的IDEA版本一定有问题,不知何故进入了无法正确解释代码的状态。

【讨论】:

    猜你喜欢
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多