Home » Spring Boot

Tag Archives: Spring Boot

Receive Pub/Sub messages to your Spring Application

spring-interview-questions-answers

Pub/Sub is a messaging solution provided by GCP Before we dive into the actual configuration we need to be aware that Spring Cloud for GCP is now managed by the Google Cloud Team. Therefore the latest code can be found here. Our application will receive messages from Pub/Sub and expose them using an endpoint.Let’s go for the imports first <?xml ...

Read More »

Providing useful API error messages with Spring Boot

spring-interview-questions-answers

For API users it is quite important an API provides useful error messages. Otherwise, it can be hard to figure out why things do not work. Debugging what’s wrong can quickly become a larger effort for the client than actually implementing useful error responses on the server side. This is especially true if clients are not able to solve the ...

Read More »

Testing the File Upload API in Spring Boot

spring-interview-questions-answers

In one of my previous post, I had created an API to upload file. In this post I will write a JUnit test to test the API. We will test the complete flow right from uploading till it is copied to the file system and then we will also see how to mock the FileService class so that the uploaded ...

Read More »

Upload files in Spring Boot application using Commons FileUpload

spring-interview-questions-answers

In our previous post, we saw how to upload a file using the Spring framework’s default implementation for MultipartFile interface. In this post, we will see how we can use the Commons FileUpload library and the wrapper implementation CommonsMultipartFile provided by the Spring framework. Update the pom.xml We will update the maven dependencies to include commons-io and commons-fileupload. We will ...

Read More »

Uploading files in Spring Boot application

spring-interview-questions-answers

Uploading files is one of the most common operations in a web application. In this article we will look at how to upload file from an HTML page and copy it to the file system on the server. Creating a HTML form with file upload option The below HTML code and its corresponding Javascript code creates the HTML form and ...

Read More »

Validation in Spring Boot applications

spring-interview-questions-answers

Validation in Spring Boot applications can be done in many different ways. Depending on your requirements some ways might fit better to your application than others. In this post we will explore the usual options to validate data in Spring Boot applications. Validation is done by using the Bean Validation API. The reference implementation for the Bean Validation API is ...

Read More »

Spring Boot for war

spring-interview-questions-answers

Spring Boot supports the following embedded servlet containers: Tomcat Jetty Undertow You can use Maven, Gradle, or Ant/Ivy as build tools to generate the jar file. However, you may need to use your own server as WebLogic, Wildfly, JBoss, etc. In that case, you would need to generate a WAR file of your Spring Boot project. To do that you ...

Read More »

Run method on Spring Boot startup

spring-interview-questions-answers

While developing a spring boot application, sometimes we need to run a method or a piece of code at startup. This code can be anything ranging from, logging certain information to setting up database, cron jobs etc. We cannot just put this code in constructor, because required variables or servies may not be initialized yet. This could lead to null pointers or some ...

Read More »