SB Ashok It
SB Ashok It
Q. 7 Spring Bean ?
It is an object
This object is completed created, linked with another object and destroy by using
container itself.
An object the entire process control by spring IOC I actually spring bean.
This object are take care configuration file with the help of configuration
file(Spring container )
@Autowired @Inject
1) It is use for dependency injection. 1) it is use for dependency injection
2)@Autowired given in spring 2) @Inject is given by java double e
framework. framework.
3) In case of String application objects 3) In case of non-String application
are spring application. then we use objects are java double e application
@Autowired. are then @Inject we use.
4) Mostly used this nowadays. 4) CDI concept was use I java double e.
5) Here @Autowired done by Spring 5) Here inject is not from spring
framework. framework it is from pure java.
Q.20 What are the different ways of writing life cycle methods in spring ?
1)There are three ways we can write lifecycle methods using xml(called as
declarative approach)
By writing bean tag, at bean tah level ,we can pass init-method, that method pass
the method name and destroy happen.
Example: <bean init-method=”” destroy-method=””></bean>
2) using spring interfaces(called as programmatic approach)
There are two interface given implement interface:initializationBean,
Disposablebean. We have to implement this interface and override the methods.
Using annotation @Poststruct and @PreDestory(This methods are optinal)
Q.21 What are the common implementation of applicationContext?
applicationContext means spring container. It is an interface.
The first implemtation, Filesystemxmlapplication context, you can have this xml
file wherever in the project or outside of the project in your system. It can be
loaded, we need.
Write full path of xml file
2) classpathxmlApplicationContext :it is also class, it is inside the
project/src/resource folder your xml file must present inside the project. In the
classpath or classpath location where you saved in os.
3) webxmlApplicationContext :generally we used to implement web based
application using web xml configuration file like servlet other implementation
@configureApplicationcontext and configurableApplicationContext and so on.
AOP instrumentation
Q.36 How to map controller class and it’s methods with url ?
When we extract the data incoming request URL that is send by / symbol
representation, you want to read that by using method handler parameter
Q.39 which annotations are used to define Global Exception Handler class?
Here we use @ Controller Advice or@Rest ControllerAdvice along with
@Exceptionhandler.
Generally we can use try-catch block but in case of repeated try-catch block are
there. i want to define all for common exception in one place, so I have go for
Generic exception handling code we can we .
If u are using web mvc the @ControllerAdvice
If u are using webRest @RestControllerAdvice.
we need to define one user class with annotation @ControllerAdvice or
@RestControllerAdvice
Then we need to define one method at top of method @ExceptionHandler in
parameter. we can mension exception type like usernotFoundException,
insuffiecientBalanceException, parameterTypeException, exception .
why can't use @ Restcontroller with Responsebody, Yes we can use and we can
get output, but standard is @RestController you have to use that If you are
implementing Restfulweb services and Request process.
Q.47 what is the main difference between Spring Care and Spring MVC?
spring care is basic concept, that is handle object mechanism and all.
object mechanism and all.
where spring mvc build top of spring core
spring core is actually called as IOC container to (dependency injection) in various
bean classes.
where spring mvc internally uses IOC mechanism work for web application
implement
spring container concepts like: container system, Beans, scheduling, AOP etc. are
part of spring core.
Q.48 what are the ways of reading data from the form in spring mvc?
If your request form is submited then we use legacy technique
HttpServletRequest as a method parameter, and we can use
Request.getparameter but the default always return sting representation, you
have to do manual conversion.
[ HttpServletRequest interface: The HttpServletRequest is a Java interface
present in Java.servlet.http package]
@RequestParam that is also read the data even it is support type conversion.
[@RequestParam: The @RequestParam reads the data binds it automatically to
the parameter. ]
we can use, @ModelAttribute, entire form in to one object, all are method
parameter only here.
[ @Model Attribute: The @ModelAttribute binds a method parameter.]