My blog article URL
What is a session
The connection between the client and the server within a limited time period
Why use session beans
Because most of EJB services are specifically provided to session beans
1. Concurrency and thread safety: Containers use many technologies to automatically ensure that developers do not have to worry about concurrency or thread safety. Thread safety issues
2. Service provision of remote processing and Web services
3. Affairs and security management
4. Interceptor
Session bean specification
1. Have at least one business interface (not required after EJB3.1)
2. The session bean must be concrete, and the session bean cannot be defined as final or abstract
3. The session bean must have a constructor without parameters
4. You can define business methods and life cycle callback methods in the session bean class or parent class
5. A session bean can be a subclass of another session bean or any other POJO. When it is a subclass of another session bean, the life cycle callback methods and dependency injection annotations defined in the parent class will be inherited by the current bean class
6. Session bean methods cannot start with "ejb". All business methods must be public and cannot be final or static methods. In addition, if the session bean is remote, all input and output parameters must implement the serialization interface
Business interface
1. Local interface: @Local Collaborative operations in the same container (JVM) instance
2. Remote interface: @Remote Collaborative operations in different container (JVM) instances are accessed through RMI
3. Web service endpoint interface: @WebService is unique to stateless beans and can expose stateless beans as SOAP-based Web services
Handling multiple business interfaces: You cannot mark the same interface with more than one access type annotation. You can choose to use the parent interface and then inherit the sub-interface to avoid code duplication
Stateless session bean
Used to model tasks that do not maintain session state
There are two creation modes, one is pooling, in which the container creates a session bean pool, creates a corresponding number of session bean examples, and manages them; the other is singleton mode (requires EJB3.1 and later versions Only supported)
Annotation: @Stateless notifies the container that this class is a stateless bean, and the container will automatically provide the bean with: concurrency control, thread safety, pooling, transaction management and other services
Stateful session bean
Used to model tasks that require maintaining session state. The EJB container will maintain the session state for us
There must be a method annotated with @Remove
Note: Select the session data appropriately and try to use data that takes up less resources; remember to use passivation and deletion
Alternative: If it is a web application, use HttpSession to maintain state
Best implementation of session bean
1. Select the session bean type, that is, whether it is a stateful bean or a stateless bean
2. Analyze session bean interface type (@Local, @Remote)
3. Do not inject stateful session beans into stateless session beans or Servlets
4. Split cross-cutting transaction items (use interceptor AOP to process)
5. Data types stored in stateful session beans (choose carefully)
6. Stateful session beans must define @Remove annotated methods
The above is the detailed content of What is a session? Why use session beans?. For more information, please follow other related articles on the PHP Chinese website!

前言公司有个项目,时间比较赶,而且项目的部分需求,和之前做的项目部分功能一样,为了赶速度和直接将之前多模块的maven项目中的部分模块,直接以jar包的形式引入到新项目中了,虽然省去了不少开发时间,但是造成项目需要导入引入项目jar的相关依赖,导致项目臃肿,启动很慢。有没有办法让项目只加载自己需要的bean呢?当然我们可以直接修改源代码重新打包引入去解决,但是这个办法太多麻烦。通过百度的手段,查询可以在springboot启动类上用@ComponentScan注解去实现代码示例@Componen

在Slim框架中使用会话(Sessions)实现用户登录和注销的方法简介:会话(Sessions)是Web应用程序中常用的一种技术,它可以用来存储和管理用户相关的数据,例如用户的登录状态等。Slim框架作为一个轻量级的PHP框架,提供了简洁的API来处理会话。本文将介绍如何在Slim框架中使用会话来实现用户登录和注销的功能。安装Slim框架首先,我们需要在P

1.Spring项目的创建1.1创建Maven项目第一步,创建Maven项目,Spring也是基于Maven的。1.2添加spring依赖第二步,在Maven项目中添加Spring的支持(spring-context,spring-beans)在pom.xml文件添加依赖项。org.springframeworkspring-context5.2.3.RELEASEorg.springframeworkspring-beans5.2.3.RELEASE刷新等待加载完成。1.3创建启动类第三步,创

在Slim框架中使用会话(Sessions)进行用户认证的方法在Web应用程序中,用户认证是一个重要的功能,它确保只有被授权的用户可以访问受限资源。会话(Sessions)是一种常用的认证方法,通过存储用户身份和状态信息,确保用户在整个会话期间保持认证状态。Slim框架提供了方便的工具和中间件来处理会话和用户认证。下面我们将介绍如何在Slim框架中使用会话进

在使用spring框架中我们都知道,某个类如果使用了@Service、@Autowire这种依赖注入的方式引用了其他对象,在另外一个类中,只有通过spring的IOC容重中获取这个类的实例时,那些被依赖的对象才能正确被初始化,否则那些被依赖的对象都是null。所以就有一个问题,在普通类中如何获取springioc容器中的bean(spring托管的bean)。我们都知道,在spring中ApplicationContext这个上下文对象是获取bean的基础。在springboot中,我们可以通过

SpringBean的生命周期管理一、SpringBean的生命周期通过以下方式来指定Bean的初始化和销毁方法,当Bean为单例时,Bean归Spring容器管理,Spring容器关闭,就会调用Bean的销毁方法当Bean为多例时,Bean不归Spring容器管理,Spring容器关闭,不会调用Bean的销毁方法二、通过@Bean的参数(initMethod,destroyMethod)指定Bean的初始化和销毁方法1、项目结构2、PersonpublicclassPerson{publicP

一、适用场景如果我们需要在应用程序的所有层次结构中对特定bean的启动顺序进行管理。例如,需要在应用程序启动的时候初始化某个bean。如果我们公共库中的bean被其他开发者服务用到,但是他们需要在部分场景下自定义bean,则我们需要在这些自定义的bean前面先加载公共库中的bean。二、三种实现方式在SpringBoot应用程序中,我们可以采取以下三种方式实现自己的bean优先加载:1.@Configuration注解+@DependsOn注解@Configuration注解在SpringBoo

Bean作用域和生命周期Bean作用域Bean的作用域是指Bean在Spring整个框架中的某种行为模式.比如singleton单例作用域,就表示Bean在整个Spring中只有一份,它是全局共享的,那么当其他人修改了这个值之后,那么另一个人读取到的就是被修改的值.Bean作用域分类singleton:单例作用域(默认作用域)prototype:原型作用域(多例作用域)request:请求作用域session:回话作用域application:全局作用域websocket:HTTP#注意#后4种


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
