I\'m new to Spring and started using the Sprint Tool Suite (eclipse) and see this error in a java file in my maven project: \"Content is not allowed in prolog\". This preve
For me it was because I had renamed some classes and the .springBeans file needed some manual editing.
It seems likely that the culprit was a corrupted eclipse workspace. I created a new workspace and imported the project and everything works fine. That would also explain why an external maven build didn't show any problems.
As noted in update 3, I had found some eclipse-generated xml files that had characters before the prolog. Although correcting those did not fix the problems, I didn't inspect every eclipse file with xml content (like the user prefs) to see if they had some invisible characters before the prolog.
Don't know what would have caused it to be corrupted except for perhaps force quitting eclipse during an unresponsive maven repo update but I can't be certain if that's when my troubles started. I'm just glad I can move forward.
Most likely the error was generated by the UTF-8
BOM
at the start of the XML
file - applications like Notepad
puts that at the start of the file and the Java streams cannot handle that automatically. Your XML
is correct, but the file is not UTF-8
Encoded. I've seen this before.. try copying and pasting the XML from this forum into a text editor and saving it. Also make sure that you're text editor is really saving in UTF-8
.
Also, Spring
will work just fine without any <?xml ... >
declaration so go ahead and remove the comment between the DTD
declaration and the starting element
. Remove the UTF-8
declaration. Problems with UTF-8
encoded XML
in Java
are pretty common, and not specific to Spring
.
In my case this error occured while I was renamed main class (class annotated with @SpringBootApplication) of springboot application. I don't mean this will always happen but I accidently got this error after rename this class file in STS 3.8.4.
To resolve this issue, I closed the IDE, navigate to project folder and delete the .springBeans
file. After reopened IDE, this error was gone and my IDE no longer complains about this.