控制 Java EE 项目中的范围 [英] Controlling scope in Java EE projects

查看:26
本文介绍了控制 Java EE 项目中的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java EE 项目中控制范围的方法是什么.我正在阅读有关会话、请求、应用程序范围以及某些 bean 应限于其中一个的内容.这一般是怎么做的?是通过什么类型的项目创建 bean 的,是特殊的注释,还是其他方法?根据我的经验,我注意到当在同一个包之外时,我的 bean、servlet 或 DAO 都不能相互访问,除非我注入或导入相关类.

What is the method of controlling scope in Java EE projects. I'm reading about session, request, application scope and that certain beans should be limited to one or the other. How is this generally done? Is it by what type of project the bean is created in, a special annotation, or some other method? In my experience I've noticed that when outside of the same package none of my beans, servlets or DAO's have access to each other unless I inject or import the related class.

推荐答案

我认为您正在混淆.您列出的范围适用于 JSF 支持 bean,通常与 HTTP 会话或请求相关.EJB-s 在此上下文中没有范围.要使用它们,必须使用 DI 注释(或通过 JNDI 上下文查找)注入它们.

I think you are mixing things. The scopes you listed are for JSF backing beans and are generally related to the HTTP session or request. EJB-s has no scope in this context. To use them they have to be injected using DI annotations (or alternatively via JNDI context lookup).

这篇关于控制 Java EE 项目中的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆