JUnit 5 @AfterEach annotation is replacement of @After annotation in JUnit 4.The annotated method should be executed after each @Test method in test class.
JUnit 5 @BeforeEach annotation is replacement of @Before annotation in JUnit 4. Annotated method should be executed before each @Test method in test class.
JUnit 5 @BeforeAll annotation is replacement of @BeforeClass and is used to signal that annotated method should be executed before all tests in test class.
Learn to execute junit 5 testcases in eclipse IDE. Maven has been used to import dependencies in this junit 5 example. Junit 5 Maven Dependencies To be able to execute junit 5 tests in eclipse, you will need following dependencies. junit-platform-runner in test scope: location of the JUnitPlatform runner junit-jupiter-api in test scope: API for […]
Learn to convert XMLGregorianCalendar to Date class or string value. Also learn to apply timezone changes and daylight saving effects as well.
Learn to build JAX-RS 2.0 HATEOAS links in REST resources using it’s javax.ws.rs.core.Link, javax.ws.rs.core.UriBuilder and javax.ws.rs.core.UriInfo classes.
Learn to REST build APIs using JAX-RS 2.0 and RESTEasy 3.1.2.Final ,Servlet 3.0 container, by configuring resteasy-servlet-initializer and @ApplicationPath.
SSL issues are common while working on enterprise applications, but their debugging is not easy. Mostly due to not having enough information in logs. For example, you will get an exception like this for various reasons – I/O error: java.security.NoSuchAlgorithmException: Error constructing implementation. An exception stack trace may look like this: com.howtodoinjava.aav.exception.SystemException: I/O error: java.lang.RuntimeException: […]
PropertyEditor is originally part of the JavaBeans specification. Spring also heavily uses the PropertyEditors to be able to represent properties in a different way than the object itself e.g. parsing human readable inputs from http request params or displaying human readable values of pure java objects in view layer. Spring has a number of built-in […]
Mostly for logging and security purpose, we need the information of IP address for incoming requests. In any java web application, you can get IP address using getRemoteAddr() method. String httpServletAddress = request.getRemoteAddr(); BUT, if your application is running behind a load balancer proxy and you would like to translate the real request IP that […]
To schedule job in spring boot application to run periodically, spring boot provides @EnableScheduling and @Scheduled annotations. Lets learn to use them. Let’s say you want to run job at every 10 seconds interval. You can achieve this job scheduling in below steps: 1) @EnableScheduling to Spring Boot Application class Add @EnableScheduling annotation to your […]
Spring boot’s CommandLineRunner interface is used to run a code block only once in application’s lifetime – after application is initialized. How to use CommandLineRunner You can use CommandLineRunner interface in three ways: 1) Using @Component over CommandLineRunner implementation class This one is fairly easy. 2) Implement CommandLineRunner in SpringBootWebApplication itself This is also possible. […]
Spring boot loads lots of beans internally to run your application with minimal configuration. In this example, we will learn to find out all those spring boot loaded beans and their class type information. Using ApplicationContext to get all loaded beans To execute a method automatically, when application is fully loaded, I am using CommandLineRunner […]
Learn spring boot logging configuration via application.yml file in simple and easy to follow instructions. In the default structure of a Spring Boot web application, you can locate the application.yml file under the resources folder. Table of Contents Understand default spring boot logging Set logging level Set logging pattern Set logging output to file Using […]
Learn spring boot logging configuration via application.properties file in simple and easy to follow instructions. In the default structure of a Spring Boot web application, you can locate the application.properties file under the resources folder. Table of Contents Understand default spring boot logging Set logging level Set logging pattern Set logging output to file Using […]
By default, Spring boot uses embedded tomcat server to run the application. At times, you may need to use jetty server in place of tomcat server. Spring Boot provides Tomcat and Jetty dependencies bundled together as separate starters to help make this process as easy as possible. You can use jetty with following simple steps. […]
By default, Spring boot applications started with embedded tomcat server start at port 8080. You can change default tomcat port to any other port, using any one of below technique. 1) Change default server port from application.properties file You can do lots of wonderful things by simply making few entries in application.properties file in any […]
By default, Spring boot applications are accessed by context path “/” which is default for embedded servers i.e. you can access the application directly at http://localhost:PORT/. But in production, you will deploy the application under some context root – so that you can refer the URLs for other places. Also, it is desirable to configure […]
Learn to create and configure spring boot application which uses JSP template files to render view layer. It uses embedded Tomcat server to run the application. Sourcecode Structure The files in this application are placed as given structure in image. Maven dependencies – pom.xml This application uses given below dependencies. Spring Boot Application Initializer The […]
FizzBuzz is a fun game mostly played in elementary school. The rules are simple: when your turn arrives, you say the next number. However, if that number is a multiple of five, you should say the word “fizz” (preferably with a French accent) instead. If the number is a multiple of seven, you should say […]