Preface: The company requires developers to strictly follow the sonarlint specification in the process of writing code.
Download word documents according to business needs and use template downloads. Put the word template in the resources directory to download.
The project structure is as follows
Start thinking about getting the path with the following method
String templateFile = this.getClass().getClassLoader().getResource("word/inspection.docx").getPath();
Sonarlint's specification prompt appeared when obtaining the path.
In a JEE context, using the standard getClassLoader() may not return the correct class loader. Instead, use currentThread.
Change it to the following, following the sonarlint specification:
String templateFile = Thread.currentThread().getContextClassLoader().getResource("word/inspection.docx").getPath();
The above two methods can successfully obtain the path, and the code of the second method is more standardized.