Fitted in Spring Boot using a bean definition file named application.xml

background

--I was using Spring MVC for war packaging and named the bean definition file application.xml. --I wanted to run it with Spring Boot, so I first tried to read application.xml with @ImportResource. --Place application.xml directly under src / main / resources so that it is included in classpath

phenomenon

I get the following error:

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.xml'

... stack trace ...

Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 87; Document root element "beans", must match DOCTYPE root "null".

... stack trace ...

Cause

Spring Boot's ConfigFileApplicationListener gives an error when trying to read xml as a configuration file (equivalent to application.properties) instead of a Bean definition file.

Since the default configuration file name is application and the extension supported by PropertiesPropertySourceLoader includes xml, application.xml is the file name to be read. Also, since the default location in the configuration file includes directly under classpath, classpath: /application.xml is read. As a result, it was a sad choice when I put application.xml directly under src / main / resources, regardless of @ ImportResource.

Workaround

--Rename the file It's not good to use the name application.xml somehow in the first place. If you make it according to the Spring Framework documentation, it will probably be ʻapplicationConfig.xml, so ordinary people will not encounter it. --Java It may be a good time to convert this to @Configuration`.

Recommended Posts

Fitted in Spring Boot using a bean definition file named application.xml
Overwrite bean definition in spring xml configuration file with another xml
What is a Spring Boot .original file?
Static file access priority in Spring boot
Local file download memorandum in Spring Boot
DI SessionScope Bean in Spring Boot 2 Filter
File output bean as JSON in spring
Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
Run a Spring Boot project in VS Code
Create a Spring Boot application using IntelliJ IDEA
How to add a classpath in Spring Boot
Java tips-Create a Spring Boot project in Gradle
How to bind to property file in Spring Boot
[Note] Configuration file when using Logback with Spring Boot
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
How to create a Spring Boot project in IntelliJ
[Introduction to Spring Boot] Submit a form using thymeleaf
Test field-injected class in Spring boot test without using Spring container
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3
I made a simple MVC sample system using Spring Boot
How to control transactions in Spring Boot without using @Transactional
Set context-param in Spring Boot
File upload with Spring Boot
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
Try using Spring Boot Security
RSocket is supported in Spring Boot 2.2, so give it a try
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Get a proxy instance of the component itself in Spring Boot
[Java] Get data from DB using singleton service in Spring (Boot)
Uploading and downloading files using Ajax in Spring Boot (without JQuery)
Let's write a test code for login function in Spring Boot
Unknown error in line 1 of pom.xml when using Spring Boot in Eclipse
Spring Boot Hello World in Eclipse
Spring Boot application development in Eclipse
Spring Boot Tutorial Using Spring Security Authentication
Write test code in Spring Boot
Upload a file using Java HttpURLConnection
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Implement Spring Boot application in Gradle
A memo that touched Spring Boot
Thymeleaf usage notes in Spring Boot
Create a Spring Boot project in intellij and exit immediately after launching
Autowired fields in a class that inherits TextWebSocketHandler in Spring Boot become NULL
Procedure to make the value of the property file visible in Spring Boot
I got stuck using snake case for variable name in Spring Boot
Java beginner tried to make a simple web application using Spring Boot
Steps to create a simple camel app using Apache Camel Spring Boot starters
Decrypt the entire bean in a properties file with some values encrypted