为什么application.xml不能用作弹簧启动应用程序的配置文件?

时间:2019-02-18 21:54:04

标签: spring-boot configuration

我正在玩spring-boot initializr,发现一些我不太了解的东西。

我创建了一个仅具有Web依赖项的全新项目,并添加了带有@Configuration@ImportResource批注的单个bean。

@Configuration
@ImportResource({"classpath*:application.xml"})
public class CollectionConfig {

然后我添加一个空的xml bean文件-application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
</beans>

运行应用程序时出现错误: Caused by: org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null"

但是,将文件名从application.xml更改为任何其他名称(例如applicationContext.xmlmyBeansInAFile.xml都会使应用程序正常启动。

我在默认的spring-boot-web应用程序的类路径上找不到任何其他application.xml文件。也许是保留字吗?我觉得这里缺少基本的东西,但是找不到任何参考。

本质上,我想了解为什么在春季启动中不允许使用名为application.xml的xml文件。

0 个答案:

没有答案