使用 <import> 时出现 Spring/Eclipse 'referenced bean not found' 警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2868412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:45:35  来源:igfitidea点击:

Spring/Eclipse 'referenced bean not found' warning when using <import>?

xmleclipsespringwarningsjavabeans

提问by HDave

I have just broken up a Spring bean configuration file into smaller external files and have used the the "import" directive to include them in my Spring Test application context XML file.

我刚刚将 Spring bean 配置文件分解为较小的外部文件,并使用“import”指令将它们包含在我的 Spring Test 应用程序上下文 XML 文件中。

But whenever I reference one of the beans from the imported files I get a warning within Eclipse/STS/Spring XML editor complaining that "referenced bean 'foo' not found"

但是每当我从导入的文件中引用其中一个 bean 时,我都会在 Eclipse/STS/Spring XML 编辑器中收到警告,抱怨“找不到引用的 bean 'foo'”

Is this is a bug or is it me? It's really annoying because I don't want to disable the warning, yet at my company we try to eliminate all warnings.

这是一个错误还是我?这真的很烦人,因为我不想禁用警告,但在我的公司,我们试图消除所有警告。

回答by Espen

It really annoyed me too!

也真的让我很生气!

I'm not sure when this feature was introduced, but with later versions it's possible to add this support.

我不确定何时引入此功能,但在更高版本中可以添加此支持。

  1. Right click on your project in the Spring explorer view
  2. Click on properties
  3. See image below:
  1. 在 Spring 资源管理器视图中右键单击您的项目
  2. 点击属性
  3. 见下图:

alt text

替代文字

I don't understand why it's not checked by default, but it works like a charm after you have enabled it!

我不明白为什么默认情况下不检查它,但是在您启用它后它就像一个魅力!

If you don't have this option with your version, I will highly recommend to download SpringSource's STSwith all necessary Eclipse plugins bundled.

如果您的版本没有此选项,我强烈建议您下载 SpringSource 的STS,并捆绑所有必需的 Eclipse 插件。

回答by VonC

According to this thread, this could be similar to:

根据这个线程,这可能类似于:

I have an (admittedly cosmetic) issue with the Spring IDE plugins for Eclipse that I've not been able to solve. I have a situation in which context files A and B are both imported by context C. B makes use of several beans defined in A, but since they're never used independently (only by C), this isn't a problem.

However, the Spring IDE plugin validator marks all of the references to beans in A in context file B as errors, saying something like "Referenced bean 'foo' not found bar.xml". Obviously this is a correct statement, but in my use case it's not an error.

there are two ways of solving this issue:

  1. Only configure context C with Spring IDE and let the other files (A. B) handled by the import support. Doing so will not create the warning. Make sure that you don't add A and B as config files to Spring IDE as they would also be validated stand-alone which causes the validation error you are seeing.
  2. Configure a Config Set for A, B, and C and don't enable Import processing for the project.

我有一个关于 Eclipse 的 Spring IDE 插件的(不可否认的装饰性)问题,我一直无法解决。我有这样一种情况,其中上下文文件 A 和 B 都由上下文 C 导入。B 使用了 A 中定义的几个 bean,但由于它们从未独立使用(仅由 C),因此这不是问题。

但是,Spring IDE 插件验证器会将上下文文件 B 中对 A 中的 bean 的所有引用标记为错误,例如“Referenced bean 'foo' not found bar.xml”。显然,这是一个正确的陈述,但在我的用例中,这不是错误。

有两种方法可以解决这个问题:

  1. 仅使用 Spring IDE 配置上下文 C,并让导入支持处理其他文件 (A.B)。这样做不会产生警告。确保您没有将 A 和 B 作为配置文件添加到 Spring IDE,因为它们也会被独立验证,这会导致您看到的验证错误。
  2. 为 A、B 和 C 配置配置集,并且不要为项目启用导入处理。

回答by Sean Patrick Floyd

1) It's noble to try to eliminate all warnings, but don't expect to succeed. 10 warnings per project are ok, 500 are not.

1) 尝试消除所有警告是高尚的,但不要期望成功。每个项目 10 个警告是可以的,500 个不是。

2) that said, it's not your bug, it's a feature that's deliberately missing from STS. deliberately, because they have no way of knowing what your runtime classpath will be. Of course they could resolve someimport statements, but that would be inconsistent behavior. in short, I have learned to live with this warning

2)也就是说,这不是您的错误,而是 STS 故意缺少的功能。故意的,因为他们无法知道您的运行时类路径是什么。当然,他们可以解决一些导入语句,但这将是不一致的行为。简而言之,我已经学会接受这个警告