标签:base body because singleton rri ports rac ... only
It is a lightweight, loosely coupled and integrated framework for developing enterprise applications in java.
IOC (Inversion of Control) and DI (Dependency Injection) is a design pattern to provide loose coupling. It removes the dependency from the program.
Let‘s write a code without following IOC and DI.
Now, there is dependency between Employee and Address because Employee is forced to use the same address instance.
Let‘s write the IOC or DI code.
Now, there is no dependency between Employee and Address because Employee is not forced to use the same address instance. It can use any address instance.
IOC container is responsible to:
There are two types of IOC containers in spring framework.
BeanFactory is the basic container whereas ApplicationContext is the advanced container. ApplicationContext extends the BeanFactory interface. ApplicationContext provides more facilities than BeanFactory such as integration with spring AOP, message resource handling for i18n etc.
No. | Constructor Injection | Setter Injection |
---|---|---|
1) | No Partial Injection | Partial Injection |
2) | Desn‘t override the setter property | Overrides the constructor property if both are defined. |
3) | Creates new instance if any modification occurs | Doesn‘t create new instance if you change the property value |
4) | Better for too many properties | Better for few properties. |
Autowiring enables the programmer to inject the bean automatically. We don‘t need to write explicit injection logic.
Let‘s see the code to inject bean using dependency injection.
The autowiring modes are given below:
No. | Mode | Description |
---|---|---|
1) | no | this is the default mode, it means autowiring is not enabled. |
2) | byName | injects the bean based on the property name. It uses setter method. |
3) | byType | injects the bean based on the property type. It uses setter method. |
4) | constructor | It injects the bean using constructor |
The "autodetect" mode is deprecated since spring 3.
There are 5 bean scopes in spring framework.
No. | Scope | Description |
---|---|---|
1) | singleton | The bean instance will be only once and same instance will be returned by the IOC container. It is the default scope. |
2) | prototype | The bean instance will be created each time when requested. |
3) | request | The bean instance will be created per HTTP request. |
4) | session | The bean instance will be created per HTTP session. |
5) | globalsession | The bean instance will be created per HTTP global session. It can be used in portlet context only. |
Singleton scope should be used with EJB stateless session bean and prototype scope with EJB stateful session bean.
Spring framework provides two type of transaction management supports:
Less code: By using the JdbcTemplate class, you don‘t need to create connection,statement,start transaction,commit transaction and close connection to execute different queries. You can execute the query directly.
You can fetch records from the database by the query method of JdbcTemplate. There are two interfaces to do this:
NamedParameterJdbcTemplate class is used to pass value to the named parameter. A named parameter is better than ? (question mark of PreparedStatement).
It is better to remember.
The SimpleJdbcTemplate supports the feature of var-args and autoboxing.
AOP is an acronym for Aspect Oriented Programming. It is a methodology that divides the program logic into pieces or parts or concerns.
It increases the modularity and the key unit is Aspect.
AOP enables you to dynamically add or remove concern before or after the business logic. It is pluggable and easy to maintain.
AOP terminologies or concepts are as follows:
JoinPoint is any point in your program such as field access, method execution, exception handling etc.
No, spring framework supports method execution joinpoint only.
Advice represents action taken by aspect.
There are 5 types of advices in spring AOP.
Pointcut is expression language of Spring AOP.
Aspect is a class in spring AOP that contains advices and joinpoints.
Introduction represents introduction of new fields and methods for a type.
Target Object is a proxy object that is advised by one or more aspects.
Interceptor is a class like aspect that contains one advice only.
Weaving is a process of linking aspect with other application.
No, spring framework performs weaving at runtime.
There are 3 AOP implementation.
The DispatcherServlet class works as the front controller in Spring MVC.
The @Controller annotation marks the class as controller class. It is applied on the class.
The @RequestMapping annotation maps the request with the method. It is applied on the method.
The View Resolver class resolves the view component to be invoked for the request. It defines prefix and suffix properties to resolve the view component.
The org.springframework.web.servlet.view.InternalResourceViewResolver class is widely used.
Yes.
标签:base body because singleton rri ports rac ... only
原文地址:https://www.cnblogs.com/vicky-project/p/9191688.html