【问题标题】:Can I make Eclipse recognise Spring beans across multiple XML files?我可以让 Eclipse 跨多个 XML 文件识别 Spring bean 吗?
【发布时间】:2014-02-14 05:02:29
【问题描述】:

我的应用程序从两个 XML 文件加载 Spring bean 定义:

String[] beandefs = new String[] {
        "commonConfig.xml",
        "specificConfig.xml"
  };
  ApplicationContext context = new ClassPathXmlApplicationContext(
        beandefs);

这是因为commonConfig.xml 包含我想要在所有部署中使用的定义。 specificConfig.xml 具有我在测试部署中替换为其他实现的定义。

这很好用,除了一个 bean 引用另一个文件中的另一个 bean 时,Eclipse (STS) 会用警告标记它。

例如如果commonConfig.xml 包含:

  <bean id="foo" class="com.example.Foo">
    <property name="bar" ref="bar" />
  </bean>

...和specificConfig.xml 包含:

  <bean id="bar" class="com.example.Bar">
       ...
  </bean>

应用程序运行良好,但 Eclipse 在commonConfig.xml 发出警告:

 Referenced bean 'bar' not found.

如何让 Eclipse 查看这两个文件?

【问题讨论】:

    标签: eclipse spring spring-tool-suite


    【解决方案1】:

    是的:您必须在“Spring Explorer”视图中打开“Beans”元素,在那里您可以配置应加载的不同文件(选项卡“configFiles”)并在选项卡“配置集”中创建一个new Config 设置并定义属于这个上下文的xmls。

    【讨论】:

      【解决方案2】:

      是的,您所做的就是创建一个“配置集”。要找到它,请转到项目属性。然后折叠“Spring”并选择“Bean Support”。其中一个选项卡是“配置集”。

      【讨论】:

      • 谢谢。由于屏幕截图,接受了@Ralph 的回答,但感谢这个同样正确的回答。
      猜你喜欢
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 2010-09-17
      • 2011-12-07
      • 1970-01-01
      相关资源
      最近更新 更多