September 25, 2018

Sreekanth B

Samsung Spring MVC Recently Asked Interview Questions Answers

What is Weaving in Spring?

Weaving is the process of linking aspect with other application types or object to create an advised object. This can be performed at compile time, runtime and load time. In spring framework weaving is performed at runtime.

What is AOP Proxy?

AOP proxy is an object to implement the aspect contracts (advice method executions and so on). The AOP proxy is object is created by the AOP framework. In spring framework AOP proxy is JDK dynamic proxy or CGLIB proxy.

What is front controller in Spring MVC?

The Front Controller is basically a type of Design pattern which are being implemented in different framework (e.g. Struts and Spring MVC etc.).

In Spring MVC DispatcherServlet act as a Front Controller for the framework and responsible for intercepting every request and then dispatches/forwards request to appropriate controller. Configure the DispatcherServlet in the web.xml file of web application and request which we want to be handled by DispatcherServlet should be mapped using URL mapping.

For example all the requests ending with *.do will be handled by the DispatcherServlet.

Samsung Spring MVC Recently Asked Interview Questions Answers
Samsung Spring MVC Recently Asked Interview Questions Answers

Difference between FileSystemResource and ClassPathResource.

In FileSystemResource you need to give the configuration file (i.e. spring-config.xml) relative to your project or the absolute location of the file.

In ClassPathResource spring looks for the file in the ClassPath so configuration (i.e. spring-config.xml) file should be included in the classpath. If spring-config.xml is in classpath, you can simply give the name of the file.

For Example: If your configuration file is at src/main/java/com/test/loadresource then your
FileSystemResource would be:
FileSystemResource resource = new FileSystemResource("src/main/java/com/test/loadresource/spring-config.xml");
And ClassPathResource would be :
ClassPathResource resource = new ClassPathResource("com/test/loadresource /spring-config.xml");

What is inner Bean Definition?

A bean definition added inside the property or constructor-arg elements are called inner bean.

- Example :
<bean id="outerbean" class="...">
<!-- instead of using a reference to a target bean, simply define the target bean inline -->
<property name="targetbean">
<bean class="com.example.Person"> <!-- this is the inner bean -->
<property name="name" value="XYZ"/>
<property name="age" value="35"/>

Give examples of how spring platform can be used by an application developer.

The spring platform can be used by an application developer in the following way :

Java method can be made to execute in a database transaction without having to deal with transaction APIs.

Local Java method can be made a remote procedure without having to deal with remote APIs.
Local Java method can be made a management operation without having to deal with JMX APIs.
Local Java method can be made a message handler without having to deal with JMS APIs.

What are the various ways of using spring?

There are various ways and forms in which springs can be used.
They are listed as follows:

1. Full-fledged Spring web app.

2. Spring middle-tier provides help of a third-party web framework.

3. Remote usage scenario: allow the system to be used to remotely use the resources from the server. The remote usage can be done to grab the data from the server or for troubleshooting the environment.

4. EJB -- Wrapping existing POJOs.
Specify the locations where spring can publish its artifacts.

Spring generally publishes its artifacts to four different places:

1. Community download site

2. Maven Central, which is considered the default repository that Maven queries, and does not require any special configuration to use.

3. The Enterprise Bundle Repository (EBR), which is considered to be run by SpringSource and also hosts all the libraries that integrate with Spring.
4. Public Maven repository hosted on Amazon S3 for the development of snapshots and milestone releases. The jar file names are given in the same form as Maven Central, which makes it a useful place to get development versions of Spring to use with other libraries Spring Framework deployed in Maven Central.

What are the features of the new spring build system in use now days?

Now the new Spring build system is used which comes with the following features :

1. "Spring Built" system which is based on Ivy.

2. consistent procedure for deployment.

3. dependency management which is made consistent.

4. consistent generation for OSGi.

List in brief the new features Spring 3.0 has to offer.

Spring 3.0 offers the following new features:

1. Spring Expression Language.

2. IoC enhancements or Java based bean metadata.

3. field formatting and General-purpose type conversion system.

4. Object to XML mapping functionality (OXM) moved from Spring Web Services project.

5. Comprehensive REST support.

6. @MVC additions.

7. Declarative model validation.

8. Early support for Java EE 6.

9. Embedded database support.

What are the annotations supported by the spring framework?

Due to addition of some core features from the JavaConfig project to the Spring Framework,the following annotations are now directly supported :

Explain in brief the metadata contained in the BeanDefinition objects.

Bean definitions contain the following metadata:

1. A package-qualified class name: which is the actual implementation class of the bean being defined.

2. Bean behavioral configuration elements, which state the procedure for how the bean should behave in the container

3. References to other beans that are required for the bean to do its work; these references are also called collaborators or dependencies.

4. Other configuration settings to set when a new object is created, for example, the number of connections to use in a bean that manages a connection pool or the size limit of the pool.

What are the different properties the metadata translates into to make up the bean definition?

Metadata translates into the following properties to make up:

1. Property defined in class the section called “Instantiating beans”.

2. Property defined in name the section called “Naming beans” scope constructor arguments the section known as “Dependency injection”.

3. Properties the section known as “Dependency injection” auto wiring mode the section known as “Autowiring collaborators”.

4. lazy-initialization mode the section called “Lazy-initialized beans”.

5. Initialization method the section called “Initialization callbacks”.

6. Destruction method the section called “Destruction callbacks”.

Briefly describe the 2 ways in which the class property can be used.

The class property can be put to use in the following ways:

1. It is used to specify the java bean for class to be constructed when container directly creates java bean by calling constructor reflectively. This procedure is also used for java code which uses a new operator.

2. It is also used to specify the class which contains static factory method which is invoked for creating object. Another case in this which doesn’t occur much is when static factory method is invoked by container on a class for creating the bean.

Explain the dependency resolution process.

The dependency resolution process is carried out as follows:

1. Creation an initialization of application text inside configuration metadata( can be specified in XML, java code,annotations) is done. This describes all the beans.

2. For each bean, its dependency is expressed in the form of properties, constructor arguments, or
arguments to the static-factory method if that is used instead of a normal constructor.

3. Each property or constructor argument is actual definition of the value which belong to set, or a reference to another bean which is in the container.

4. Each property or constructor argument which is a value is gone through conversion from its specified format to the actual type of that property or constructor argument.

How can you use spring to resolve collaborators for your bean? Also state the advantages of auto wiring?

The spring can be used to resolve collaborators automatically by inspecting contents of the ApplicationContext.

The Autowiring has the following advantages in spring:

1. Reduces requirement for specifying properties or construction arguments.

2. Updates configuration while evolving of objects. To understand this lets consider an example: modifying would not be required in configuration of a dependency while adding it to a class.

3. Switching to explicit wiring when code base is stable can be neglected.

List the limitations of auto wiring.

Autowiring has the following limitations :

1. Overriding and auto wiring are caused due to dependency in property and constructor argument setting.

2. Less precise as compared to explicit wiring.

3. Tools that generate documentation using a spring might not have access to wiring information.

4. There is a possibility of clash between bean definitions and argument or method to be wired.

5. The problem does not occur much in case of maps, arrays and collection and cannot be resolved randomly for dependencies which expect one value.

In scenarios where you have to avoid using auto wiring, what are the other options that can be explored to achieve the same?

In scenarios where using autowiring is prohibited, the following replacements can achive the same :

1. Abandon autowiring for favor of explicit wiring.

2. Avoid autowiring for a bean definition by setting the autowire-candidate for attributes to false as
described in the next section.

3. Set a single bean definition as the primary candidate by setting the primary attribute of its <bean/> element to true.

4. When Java 5 or later is used, implementation needs more fine-grained control available with annotation-based configuration.

How do you call the multiple life cycle mechanisms configured for the same bean?

Multiple lifecycle mechanisms which are configured for the same bean, with different initialization methods, are called by the following ways :

1. Methods annotated with use of @PostConstruct.

2. afterPropertiesSet() as stated by the InitializingBean callback interface.

3. Custom configuration init() method

Destroy methods are called in the same order as follows :

1. Methods annotated with the use of @PreDestroy.

2. destroy() as stated by the DisposableBean callback interface.

3. destroy() method with custom configuration.

What are the methods associated with the FactoryBean interface?

Following are the methods associated with factory bean interface:

1. Object getObject() : This returns an instance of the object which the factory creates. This instance can possibly be shared, depending on the factory returns singletons or prototypes.

2. Boolean isSingleton() : This returns true if this FactoryBean returns singletons, otherwise false.

3. Class getObjectType() : This returns the object type returned by the getObject() method or null if the type is unknown in advance.

What is default scope of bean in Spring framework ?

The default scope of a Spring bean is Singleton scope.

Does Spring singleton beans are thread-safe ?

No, Spring singleton beans are not thread-safe. Singleton doesn't mean bean would be thread-safe.

What is dependency Injection?

Dependency Injection is one of the design pattern, which allows injecting dependency on Object, instead of object resolving the dependency.

Subscribe to get more Posts :