log4j2.xml:2:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.

How to solve log4j2.xml:2:6: The processing instruction target matching “[xX][mM][lL]” is not allowed.

這篇介紹How to solve log4j2.xml:2:6: The processing instruction target matching “[xX][mM][lL]” is not allowed.

發生錯誤的file

1
2
3
4
5
6
7
$ 1
$ 2 <?xml version="1.0" encoding="UTF-8"?>
$ 3 <Configuration status="error">
$ 4 <Properties>

當log4j2.xml檔案的<?xml version="1.0" encoding="UTF-8"?> 在第二行時
就會出現此錯誤訊息。

解決方法

1
2
3
4
5
6
$ 1 <?xml version="1.0" encoding="UTF-8"?>
$ 2 <Configuration status="error">
$ 3 <Properties>

將<?xml version="1.0" encoding="UTF-8"?>移至log4j2.xml檔案的第一行
即可解決此錯誤發生。