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

查看:79
本文介绍了在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天全站免登陆