eclipse - 我可以让 Eclipse 识别多个 XML 文件中的 Spring bean 吗?

标签 eclipse spring spring-tool-suite

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

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

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

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

例如如果 commonConfig.xml 包含:

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

...和specifiedConfig.xml包含:

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

应用程序工作正常,但 Eclipse 在 commonConfig.xml 中发出警告:

 Referenced bean 'bar' not found.

如何告诉 Eclipse 查看这两个文件?

最佳答案

是的:您必须在“Spring Explorer” View 中打开“Beans”元素,您可以在其中配置应加载的不同文件(选项卡“configFiles”),并且在选项卡“config Sets”中您可以创建一个新的配置集并定义属于此上下文的 xml。

enter image description here

关于eclipse - 我可以让 Eclipse 识别多个 XML 文件中的 Spring bean 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21311714/

相关文章:

java - Eclipse 订单和导出

java - 通过 Eclipse IDE 运行程序参数

Eclipse 在运行或调试期间不使用 gradle dependencies jar

eclipse - 从使用 SableCC 创建的解析器开始的 Eclipse 自定义文本编辑器

java - 自定义 ExceptionMapper 在 Spring + Jersey + Jetty 中不起作用

spring - 使用spring和gradle的java.lang.LinkageError

java - 在 Spring Security 中实现大量级联角色和权限的更好方法?

Web 应用程序库中的 Eclipse Gradle 依赖项未更新

java - Ant build.xml 中的 Cobertura “unable to locate file”

java - Spring Boot : SpringApplication. 运行导致 org.springframework.context.ApplicationContextException: