Super IOC container supercontainer

Source: Internet
Author: User

In Java EE and other Java applications, containers are very important. Web containers, Applet containers, and EJB containers are everywhere.
From the programmer's point of view, the IOC container is a very good thing. It allows us to manage components and dependencies flexibly. Spring relies on a comprehensive and flexible IOC container to make a fortune. As the fifth article in The easyjweb feature series, let's take a look at the features of IOC containers in easyjweb.
If you have read the easyjweb1.0 introduction, you will find that it is not just a MVC. To achieve good management of business objects for core MVC calls, we provide a super IOC container in easyjweb. This "super" is reflected in the fact that it is a container in the container. It can accommodate other excellent containers and organically combine the individual in these independent containers according to their needs, complete what we need to do.
Of course, easyjweb also provides a simple IOC container. If you do not want to or have no access to other containers, you can simply use the IOC container of easyjweb, it can also write very elegant and loosely coupled javaee applications.
Containers are easy to use and fully configurable. You can include spring containers, guice containers, and even EJB containers into supercontainer of easyjweb as needed. Let them work for you in their respective specialized fields. Check the Code:

@ Inject (name = "persondao ")
Private genericdao <person> Dao;
Public void setdao (genericdao <person> Dao )...{
This. Dao = Dao;
}

In the preceding crudaction example, personaction requires a Dao to work. Here we declare that we use genericdao <person>, where does the DaO come from during the specific running process of the program, where is it stored? Easyjweb does not care about these things. You only need to use the @ inject label to tell us to enable an object named persondao from the Super IOC container. In this way, easyjweb searches for the persondao object from the Super IOC container and injects it into the action, so that our action can work normally.
Implementing dependency injection and control inversion is nothing special. Every IOC framework can implement this function. The difference is that easyjweb can not only get dependency objects from its own IOC container, but also get this object from any other IOC container. For example, we can configure the persondao in the spring container, or use guice to manage the persondao, or directly store the persondao In the EJB container of another server. Easyjweb automatically searches for these locations and coordinates them.
With the super IOC container, the system administrator no longer worries about the management of the components in the business logic layer, and the boss does not need to worry about the porting cost of replacing the IOC container.
The IOC container of easyjweb also implements automatic injection by name, by category, and bean management for different lifecycles. By default, beans of the Singleton, prototype, session, and request types are supported.
In addition, in easyjweb, core components such as requestprocessor, validator, and exceptionhandler of the central processor are managed by super containers of easyjweb. Therefore, you can easily replace some components of easyjweb as needed.
Add the spring container configuration in easyjweb super container as follows:

<Bean name = "springcontainer"
Class = "org. springframework. Web. Context. Support. xmlwebapplicationcontext">
<Property name = "configlocations">
<List>
<Value> WEB-INF/classes/application. xml </value>
</List>
</Property>
</Bean>
<Bean name = "innerspringcontainer"
Class = "com. easyjf. Container. impl. springcontainer">
<Property name = "Factory" ref = "springcontainer"/>
</Bean>

 

You can configure the central processor of easyjweb in the spring container, or even configure transactions, as shown in the following spring configuration file:
 

<? XML version = "1.0" encoding = "UTF-8"?>
<Beans xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: AOP = "http://www.springframework.org/schema/aop"
Xmlns: Tx = "http://www.springframework.org/schema/tx"
Xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd ">
<Import resource = "jpa-base.xml"/>
<Import resource = "service. xml"/>
<Import resource = "Dao. xml"/>
<AOP: config>
<AOP: pointcut id = "easyjwebprocessor"
Expression = "execution (* COM. easyjf. Web. requestprocessor. Process (...)"/>
<AOP: Advisor advice-ref = "txeasyjwebprocessoradvice"
Pointcut-ref = "easyjwebprocessor"/>
</AOP: config>
<TX: Advice id = "txeasyjwebprocessoradvice"
Transaction-Manager = "transactionmanager">
<TX: Attributes>
<TX: method name = "*" propagation = "required" Read-Only = "true"/>
</TX: Attributes>
</TX: Advice>
<Bean name = "easyjweb-processor" class = "com. easyjf. Web. Core. defaultrequestprocessor"/>
</Beans>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.