Hello There!
In order to enable UTF-8 encoding on spring boot application, using VS code, follow these steps,
Add below code in application.xml/yml
server:
port: 8022
servlet:
context-path: /CMNRFQ
encoding:
charset: UTF-8
enabled: true
force: true
For maven applications, add below plugins in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<jvmArguments>-Dfile.encoding=UTF8</jvmArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
On the same pom.xml file, add below properties
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
In order to display UTF-8 enabled chars on VS code, you need to setup few things too
Go to file -> preferences -> setting and search
terminal.integrated.shellArgs
click on “Add Item” to add below command
--encoding=UTF-8
Search and open
launch.json
Add below args
"vmArgs": "-Dfile.encoding=UTF-8",
"env": {
"JAVA_TOOL_OPTIONS": "-Dfile.encoding=UTF-8"
}
Thats it. Now your application is UTF-8 enables and also VS code is enabled to display UTF-8 chars.