Friday, 15 September 2017

Java Spring Interview Questions


  1. Load application Context on Spring?
    1. ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    2. Autowired
      1. @Autowired
      2. private ApplicationContext appContext;
  2. Spring bean scopes: session and globalSession
    1. GlobalSession is something which is connected to Portlet applications. When your application works in Portlet container it is built of some amount of portlets. Each portlet has its own session, but if your want to store variables global for all portlets in your application than you should store them in globalSession. This scope doesn't have any special effect different from session scope in Servlet based applications.
  3. What is the difference between a portlet and a servlet?
    1. Portlets are part of JSR-168 standard that regulates portal containers and components. This is different standard from standards for web containers (and servlets). Though there are definitely strong parallels between these two standards they differ in containers, APIs, life cycle, configuration, deployment, etc.
    2. The main difference between portlet vs. servlet could be that while servlet always responds to single type of action - request, portlet (due to nature of its life cycle and stronger container bindings) has to respond to two types of actions: render and request. There are of course more to it but I found this as the core difference between the two when I studied portal development.
  4. Difference between spring @Controller and @RestController annotation? 
    @Controller
  • @Controller is used to mark classes as Spring MVC Controller. 
  • If we need to return values as JSON or XML then need to add @ResponseBody annotation above the method
  • @RestController 
  • Its methods will automatically converte the response to JSON or XML. No need to add @ResponseBody annotation.

@Controller @ResponseBody public class MyController { } @RestController public class MyRestController { }

No comments:

Post a Comment

Search This Blog

Contact us

Name

Email *

Message *