简体   繁体   English

Spring IDE(STS)中的配置文件配置:是否还应列出导入的XML文件?

[英]Config files configuration in Spring IDE (STS): should imported XML files be listed as well?

There's one thing I never understood after so many years of using Spring IDE and Spring Tool Suite (STS). 在使用Spring IDE和Spring Tool Suite(STS)这么多年之后,我从未了解过一件事。 I'm using XML configuration files. 我正在使用XML配置文件。 One file (say "applicationContext.xml") imports other XML files, through the use of: 一个文件(例如“ applicationContext.xml”)通过使用以下内容导入其他XML文件:

<import resource="classpath:path/to/otherContextFile.xml" />

In my Eclipse project properties, under Spring | 在我的Eclipse项目属性中的Spring | Beans Support, the option "Enable support for <import/> element in configuration files" is enabled. 启用了Beans支持选项“在配置文件中启用对<import />元素的支持”。

In the same project properties page, if the list of the configuration files only contains applicationContext.xml, STS is nevertheless able to detect the contents of otherContextFile.xml and parses it correctly. 在同一项目属性页面中,如果配置文件列表仅包含applicationContext.xml,则STS仍然能够检测otherContextFile.xml的内容并正确地对其进行解析。

However, what I see is that if STS performs an autodetection of configuration files, it always adds to that list otherContextFile.xml as well. 但是,我看到的是,如果STS执行自动检测配置文件,则它总是也将otherContextFile.xml添加到该列表中。 But adding all the imported configuration files to that list sounds like the option "Enable support for <import/> element in configuration files" is then useless to me. 但是,将所有导入的配置文件添加到该列表听起来像是选项“在配置文件中启用对<import />元素的支持”对我来说毫无用处。 Since I like to keep my project setup clean and tidy, when this happens I usually remove the imported files from that list. 由于我喜欢保持项目设置的整洁,因此通常会从该列表中删除导入的文件。

However, every now and then, the automatic scan is triggered (maybe on STS upgrade or I don't know...) and those files are re-added. 但是,时不时地会触发自动扫描(可能是在STS升级时,或者我不知道...),并且重新添加了这些文件。 This makes me think that it might be a better choice to keep them listed anyway... 这让我认为无论如何都要将它们列出来可能是一个更好的选择。

So, the question is: what is more correct, elegant and efficient (from a performance point of view)? 因此,问题是:从性能的角度来看,什么才是正确,优雅和有效的呢? Just list the "root" configuration files or all of them (even the imported ones)? 只需列出“ root”配置文件或全部(甚至是导入的)配置文件? And if the answer is the latter, what's then the point of that option "Enable support for <import/> element in configuration files"? 如果答案是后者,那么“启用对配置文件中的<import />元素的支持”选项的意义是什么?

The main purpose of the "Enable support for <import/> element in configuration files" is exactly what you are using it for and what you describe at the beginning of your question. “在配置文件中启用对<import/>元素的支持”的主要目的就是要使用它以及在问题开始时描述什么。 Therefore I think you are using it in the "right" way (from the STS tooling perspective). 因此,我认为您正在以“正确”的方式使用它(从STS工具的角度看)。

The automatic scan should not add those imported files to the list of used Spring config files in the project properties. 自动扫描不应将那些导入的文件添加到项目属性中已使用的Spring配置文件的列表中。 It does that for specific files only, like Spring Boot application main classes or files that are listed in the web app. 它仅对特定文件执行此操作,例如Spring Boot应用程序主类或Web应用程序中列出的文件。 I have no idea at the moment why those imported files are added to that list every once in a while. 我现在不知道为什么偶尔将这些导入的文件添加到该列表中。 This could be a bug or could be caused because the mechanism finds those files being used somewhere else. 这可能是一个错误,也可能是由于该机制找到了在其他地方使用的那些文件而引起的。

I would love to take a more detailed look, so it would be great if you could create a small sample app that reproduces this behavior and create a GitHub issue for this problem at: https://github.com/spring-projects/spring-ide/issues . 我想更详细地了解一下,因此,如果您可以创建一个重现此行为的小型示例应用程序,并在以下位置创建此问题的GitHub问题,那就太好了: https : //github.com/spring-projects/spring -ide /问题 Please attach the sample project and a few steps how to reproduce the issue. 请附加示例项目和一些步骤来重现此问题。

In addition to that you can disable the "automatic scanning" per project or for your entire workspace (to quickly get rid of this behavior). 除此之外,您还可以针对每个项目或整个工作区禁用“自动扫描”(以快速消除此行为)。 You can deactivate specific automatic configs via the project properties (the third tab, next to the list of config files). 您可以通过项目属性(配置文件列表旁边的第三个选项卡)停用特定的自动配置。 The "global" disable can be activated in the general "Preferences -> Spring -> Beans Support" and then "Disable Auto Config Detection". 可以在常规的“首选项-> Spring-> Beans支持”中激活“全局”禁用,然后在“禁用自动配置检测”中激活。

Hope this helps!!! 希望这可以帮助!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring中的数据库配置以及Hibernate配置文件 - Database Configuration In Spring As Well As Hibernate config files spring xml配置在两个单独的xml文件中? - spring xml configuration in two separate xml files? Spring Boot在不应该配置文件的情况下创建配置文件 - Spring boot creating configuration files when it should not Spring IDE / STS:我可以从其他文件中自动完成Bean吗? - Spring IDE / STS : Can I get autocompletions of beans from other files? 春天在哪里存储xml配置文件 - spring where to store xml config files Spring Framework:加载多个.xml配置文件 - Spring Framework : Loading multiple .xml configuration files Spring 3 Java Config:导入的@Configuration没有增强? - Spring 3 Java Config: Imported @Configuration not enhanced? Spring ResourceBundleMessageSource在Spring xml文件中配置多个属性文件? - Spring ResourceBundleMessageSource multiple properties files configuration in spring xml file? 春季-我在sts 3.5发行软件中看不到dist或projects文件夹,也看不到任何xml文件 - spring- i dont see dist or projects folder in sts 3.5 distribution software nor any xml files applicationContext.xml和其他配置文件 - 它们应该去哪里? - applicationContext.xml and other configuration files - where should they go?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM