Blog Archives

What is the difference between DispatcherServlet and ContextLoaderListener in Spring?

DispatcherServlet is the core of Spring MVC application. It loads Spring bean configuration file and initialize all the beans mentioned in config file. In case we have enabled annotations in Spring config file, it also scans the packages and configures

Posted in Spring, Spring Interview Questions

How will you handle exceptions in Spring MVC Framework?

Spring MVC Framework provides following mechanisms to help us achieve exception handling: <li><strong>Controller Based</strong>: A developer can define exception handler methods in a Controller class. To do so, they have to annotate the methods with @ExceptionHandler annotation.</li> <li><strong>Global Exception Handler</strong>:

Posted in Spring, Spring Interview Questions

What are the best practices of Spring Framework?

In Spring Framework, following are some of the best practices: We can Divide spring bean configurations based on their concerns such as spring-jdbc.xml, spring-security.xml. It is better to avoid version numbers in schema reference. This makes sure that we have

Posted in Spring, Spring Interview Questions

What is Spring Boot?

Spring Boot is a ready made solution to create Spring applications with production grade features. It favors convention over configuration. We can embed Tomcat or Jetty in in an application created with Spring Boot. Spring Boot automatically configures Spring in

Posted in Spring, Spring Interview Questions

What are the differences between Dependency Injection (DI) and Factory Pattern?

Main differences between Dependency Injection (DI) and Factory Pattern are: Coupling: Factory pattern adds tight coupling between an object, factory and dependency. In case of DI, there is no coupling between objects. We just mention the dependencies on different objects

Posted in Spring, Spring Interview Questions

In Spring framework, what is the difference between FileSystemResource and ClassPathResource?

In Spring we can specify configuration by using a file or classpath. <li>In FileSystemResource we have to give absolute path / relative path of Spring Configuration file spring-config.xml file.</li> <li>In ClassPathResource Spring looks for Spring Configuration file spring-config.xml in ClassPath.

Posted in Spring, Spring Interview Questions

Name some popular Spring framework annotations that you use in your project?

Spring has many Annotations to serve different purposes. For regular use we refer following popular Spring annotations: @Controller: This annotation is for creating controller classes in a Spring MVC project. @RequestMapping: This annotation maps the URI to a controller handler

Posted in Spring, Spring Interview Questions

How can you upload a file in Spring MVC Application?

In Spring MVC framework we can use MultipartResolver interface to upload a file. We need to make configuration changes to make it work. After uploading the file, we have to create Controller handler method to process the uploaded file in

Posted in Spring, Spring Interview Questions

What are the different types of events provided by Spring framework?

Spring framework provides following five events for Context: ContextRefreshedEvent: Whenever ApplicationContext is initialized or refreshed, Spring publishes this event. We can also raise it by using refresh() method on ConfigurableApplicationContext interface. ContextStartedEvent: When ApplicationContext is started using start() method on

Posted in Spring, Spring Interview Questions

What are the main features of Spring MVC?

Spring MVC has following main features: Clear separation of role: In Spring MVC, each role‚ÄČlike-‚ÄČcontroller, validator, command object, form object, model object, DispatcherServlet, handler mapping, view resolver etc. is fulfilled by a specialized object. Reusability: Spring MVC promotes reusable business

Posted in Spring, Spring Interview Questions