Questions #Tagged [spring-boot]

Questions: 4

How to put validations for MultipartFile in Spring Boot?

Using below code we can put validations for MultipartFile in Spring Boot:<br> <pre><xmp>private void validateExtension(MultipartFile file) { String extension = FilenameUtils.getExtension(file.getOriginalFilename()); if (!"png".equals(extension) && !"jpeg".equals(extension) && !"jpg".equals(extension)) { throw new InvalidFileExtensionException("Only jpg/jpeg and png files are accepted"); } } private void validateFileSize(MultipartFile file){ if (file.getSize() >= MAXIMUM_FILE_SIZE_ALLOWED) { throw new BusinessException("File size cannot be greater than 5 Mb"); } }</xmp></pre>

 

#java     #spring-boot     #spring    

Unable to build Spring boot project and getting error?

To fix this issue go to pom.xml and remove relativePath tag from parent tag as maven attempts to read the parent pom from a relative path on your hard drive where no relative path is specified:<br> <pre><xmp><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.5.RELEASE</version> </parent></xmp></pre>

 

#error     #spring-boot     #pom.xml     #maven    

In spring boot project I am getting unknown error in line 1 of pom.xml which is not allowing me to run the project. I have tried so many things but this error still persist. What is the solution for this unknown error?

To resolve this unknown error issue in pom.xml follow below steps:<br> &#9679 In pom.xml under parent tag change the version from 2.1.5 to 2.1.4. <pre><xmp><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent></xmp></pre> <p>&#9679 Then right click on the project and go to 'Maven' and then do 'Update project'</p>

 

#error     #spring-boot     #pom.xml     #maven    

Getting error code 403 when running spring-boot program? Is it something related to pom.xml?

403 error means Forbidden - you don't have permission to access / on this server. But in this case this issue is occurring due to Java version issue. Update your java version and move to open JDK to resolve this issue.

 

#java     #error     #core-java     #spring-boot     #pom.xml     #maven