Spring Interview Questions
- What is Spring Framework?
- What are some of the important features and advantages of Spring Framework?
- What do you understand by Dependency Injection?
- How do we implement DI in Spring Framework?
- What are the benefits of using Spring Tool Suite?
- Name some of the important Spring Modules?
- What do you understand by Aspect Oriented Programming?
- What is Aspect, Advice, Pointcut, JointPoint and Advice Arguments in AOP?
- What is the difference between Spring AOP and AspectJ AOP?
- What is Spring IoC Container?
- What is a Spring Bean?
- What is the importance of Spring bean configuration file?
- What are different ways to configure a class as Spring Bean?
- What are different scopes of Spring Bean?
- What is Spring Bean life cycle?
- How to get ServletContext and ServletConfig object in a Spring Bean?
- What is Bean wiring and @Autowired annotation?
- What are different types of Spring Bean autowiring?
- Does Spring Bean provide thread safety?
- What is a Controller in Spring MVC?
- What’s the difference between @Component, @Repository & @Service annotations in Spring?
- What is DispatcherServlet and ContextLoaderListener?
- What is ViewResolver in Spring?
- What is a MultipartResolver and when its used?
- How to handle exceptions in Spring MVC Framework?
- How to create ApplicationContext in a Java Program?
- Can we have multiple Spring configuration files?
- What is ContextLoaderListener?
- What are the minimum configurations needed to create Spring MVC application?
- How would you relate Spring MVC Framework to MVC architecture?
- How to achieve localization in Spring MVC applications?
- How can we use Spring to create Restful Web Service returning JSON response?
- What are some of the important Spring annotations you have used?
- Can we send an Object as the response of Controller handler method?
- How to upload file in Spring MVC Application?
- How to validate form data in Spring Web MVC Framework?
- What is Spring MVC Interceptor and how to use it?
- What is Spring JdbcTemplate class and how to use it?
- How to use Tomcat JNDI DataSource in Spring Web Application?
- How would you achieve Transaction Management in Spring?
- What is Spring DAO?
- How to integrate Spring and Hibernate Frameworks?
- What is Spring Security? Spring security framework focuses on providing both authentication and authorization in java applications. It also takes care of most of the common security vulnerabilities such as CSRF attack.It’s very beneficial and easy to use Spring security in web applications, through the use of annotations such as
@EnableWebSecurity
. You should go through following posts to learn how to use Spring Security framework.- Spring Security in Servlet Web Application
- Spring MVC and Spring Security Integration Example
- How to inject a java.util.Properties into a Spring Bean?
- Name some of the design patterns used in Spring Framework? Spring Framework is using a lot of design patterns, some of the common ones are:
- Singleton Pattern: Creating beans with default scope.
- Factory Pattern: Bean Factory classes
- Prototype Pattern: Bean scopes
- Adapter Pattern: Spring Web and Spring MVC
- Proxy Pattern: Spring Aspect Oriented Programming support
- Template Method Pattern: JdbcTemplate, HibernateTemplate etc
- Front Controller: Spring MVC DispatcherServlet
- Data Access Object: Spring DAO support
- Dependency Injection and Aspect Oriented Programming
- What are some of the best practices for Spring Framework? Some of the best practices for Spring Framework are:
- Avoid version numbers in schema reference, to make sure we have the latest configs.
- Divide spring bean configurations based on their concerns such as spring-jdbc.xml, spring-security.xml.
- For spring beans that are used in multiple contexts in Spring MVC, create them in the root context and initialize with listener.
- Configure bean dependencies as much as possible, try to avoid autowiring as much as possible.
- For application level properties, best approach is to create a property file and read it in the spring bean configuration file.
- For smaller applications, annotations are useful but for larger applications annotations can become a pain. If we have all the configuration in xml files, maintaining it will be easier.
- Use correct annotations for components for understanding the purpose easily. For services use @Service and for DAO beans use @Repository.
- Spring framework has a lot of modules, use what you need. Remove all the extra dependencies that gets usually added when you create projects through Spring Tool Suite templates.
- If you are using Aspects, make sure to keep the join pint as narrow as possible to avoid advice on unwanted methods. Consider custom annotations that are easier to use and avoid any issues.
- Use dependency injection when there is actual benefit, just for the sake of loose-coupling don’t use it because it’s harder to maintain.
References :
No comments:
Post a Comment