Home » Tag Archives: Spring (page 5)

Tag Archives: Spring

DispatcherServlet of Spring MVC – 10 things Java Developer should know

spring-interview-questions-answers

If you have worked with Spring MVC then you should know what is a DispatcherServlet? It’s actually the heart of Spring MVC, precisely the C of MVC design pattern or Controller. Every single web request which is supposed to be processed by Spring MVC goes through DispatcherServlet. In general, its an implementation of Front Controller Pattern which provides a single point ...

Read More »

Secure REST Service with OAuth2 Tokens

spring-interview-questions-answers

1. Introduction In this tutorial, we will check out how we can use Spring Security with OAuth to secure REST Service. In the demo application, the secured REST resources on the server are accessible with the path pattern (/api/**), such that the request URLs based on this path are mapped to different controller methods. This means that – Any REST ...

Read More »

Using Gmail as SMTP server from Java, Spring Boot apps

spring-interview-questions-answers

Gmail users can use Gmail’s SMTP server smtp.gmail.com to send emails from their Spring Boot apps. For this let us do some setup in the app: Provide SMTP connection properties in the application.properties file: spring.mail.host=smtp.gmail.com spring.mail.username=<your gmail/google app email> spring.mail.password=***** spring.mail.port=587 spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.required=true Use Spring Boot Email tools library – which is a wrapper over Spring Boot Email starter library. ...

Read More »

Lombok – you should definitely give it a try

spring-interview-questions-answers

Lombok is not a new thing in a Java ecosystem, but I must admit I always underestimated its value until I tried it or I was “convienced” to try it. I did not see much value in adding a library that generates code that can be easily generated by any modern IDE these days. So I ignored the library and ...

Read More »

Integrating Swagger with Spring Boot REST API

spring-interview-questions-answers

In the last post, I talked about my experience with creating RESTFul Services using Spring Boot. When creating a REST API, proper documentation is a mandatory part of it. What is Swagger? Swagger(Swagger 2) is a specification for describing and documenting a REST API. It specifies the format of the REST web services including URL, Resources, methods, etc. Swagger will generate ...

Read More »

Securing resources using Spring Security with OAuth

spring-interview-questions-answers

1. Introduction In this tutorial, we will check out how we can use Spring Security with OAuth to secure the admin resources on the server based on the path pattern (/api/**). Another path pattern (/oauth/token) we have configured which will help configured authorization server generate the access token. Note that we will be using Password Grant Type in this demo ...

Read More »

Mocking Spring Security Context for Unit Testing

spring-interview-questions-answers

Today, while writing unit test case for one of the Java method which looks like below: public ApplicationUser getApplicationUser() { ApplicationUser applicationUser = (ApplicationUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return applicationUser; } I want to mock Spring Security Context to get the Principal, to achieve the same I mocked each level of method calls as follows: import org.junit.Before; import org.junit.Rule; import org.junit.Test; import static org.mockito.Mockito.when; ...

Read More »