我的应用程序从两个 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。
关于eclipse - 我可以让 Eclipse 识别多个 XML 文件中的 Spring bean 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21311714/