官术网_书友最值得收藏!

The basic architecture of Java EE applications

Java EE applications are written in the Java language and run on Java virtual machine (JVM). On top of the standard Java SE functionality, the Java EE implementation provider implements a number of services, which can be used by those applications. Examples of such services may be security, transactions, or dependency injection.

Applications don't interact with enterprise services directly. Instead, the specifications define the component and containers concepts. Components are software units written in the Java language and configured and built in a similar way to standard Java classes. The difference is that metatada provided with the component allows it to be run using a runtime provided by the Java EE implementation. Such a runtime, which may differ for the different types of component, is called a container. The container is responsible for providing access to all enterprise services required by the component.

As an example, let's take a look at the following component:

package org.tadamski.examples.javaee;

import org.tadamski.examples.java.ee.model.Foo;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;

//1
@Stateless
public class FooDaoBean implements FooDao {

//2
@Inject
private EntityManager em;


public void save(Foo foo) throws Exception {
//3
em.persist(foo);
}
}

The preceding script presents an ejb component (1), that is, FooDaoBean, which is responsible for saving objects of the Foo type into the database.

The ejb container in which this component will run will be responsible for pooling instances of this component and managing the lifecycle for all of them. Furthermore, this concrete component takes advantage of the number of enterprise services: dependency injection (2), ORM persistence (3), and transactions (the default for this kind of component).

In general, the goal of the Java EE runtime is to take care of all technical aspects of enterprise applications so that the application developer can concentrate on writing business code. The preceding example demonstrates how it is realized in Java EE: the application developer writes their code using POJOs with minimal configuration (provided mostly by annotations). The code written by an application developer implements business functionalities declaratively, informing middleware about its technical requirements.

主站蜘蛛池模板: 江津市| 河西区| 莱阳市| 台江县| 南木林县| 德令哈市| 乳源| 连州市| 泗阳县| 龙陵县| 平山县| 磐安县| 古田县| 抚顺县| 凤翔县| 汉源县| 改则县| 乌鲁木齐市| 巧家县| 密山市| 安陆市| 双牌县| 霍州市| 城固县| 旌德县| 洪洞县| 怀集县| 高安市| 弥渡县| 胶南市| 定日县| 凉城县| 临猗县| 驻马店市| 宁河县| 两当县| 宁海县| 新宁县| 扎赉特旗| 喀喇| 湘潭市|