多层企业应用程序中的NBP富客户端? [英] NBP rich client in a multi-tier enterprise application?

查看:167
本文介绍了多层企业应用程序中的NBP富客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚启动了一个项目,该项目涉及在Netbeans平台(NBP)中实现的富客户端,因此选择Spring框架来实现业务逻辑和进行数据访问.由于我来自Web应用程序开发背景,因此我有一些问题,也想提出一些建议.

Just started a project that involves a rich client implemented in Netbeans Platform (NBP), Spring framework is chosen to implement business logic and for data access. Since I've come from a web application development background, I have some questions and would also like some suggestions.

  1. 富客户端与Spring集成有哪些选择?
  2. 有关多层Java EE环境中富客户端的最佳实践/书籍/文档吗?
  3. 有什么需要特别注意的吗?

推荐答案

我们最近在我所在的公司经历了类似的经历.可悲的是,我们找不到该过程的任何明确指南.我们发现的是这里和那里的部分指南.我不确定其他人如何处理此问题,我很想看看这里是否发布了其他解决方案.但是,我可以告诉您我们的处理方式,希望您可以从我们的经验中学到.

We recently went through a similar experience at the company I work for. Sadly, we couldn't find any sort of definitive guide for the process. What we found were partial guides here and there. I'm not certain how others have dealt with this issue, and I am eager to see if any other solutions are posted here. I can, however, tell you how we handled it and hope that you can learn from our experience.

从一开始,我们就知道我们希望能够控制要使用的Spring版本(在本例中为Hibernate).自然,NetBeans IDE中内置的版本有些陈旧,我们希望在开发服务器代码时拥有最先进的功能.

From the onset, we knew that we wanted to be able to control what version of Spring (and, in our case, Hibernate) we would use. Naturally, the versions built into the NetBeans IDE are a bit dated and we wanted to have the cutting-edge available when developing our server code.

我们最终要做的是创建两个单独的项目:一个用于我们的服务器代码(我们的服务,DAO和Domain实体),另一个用于我们的客户端应用程序.然后,我们打包服务器代码,将jar及其依赖项复制到客户端项目,并在客户端代码中将这些jar作为依赖项列出.我们在NetBeans项目中创建了一个名为SpringHibernate的模块,该模块容纳了这些jar,几乎每个其他模块都依赖该模块.

What we ended up doing was creating two separate projects: one for our server code (our Services, DAOs, and Domain entities) and one for our client application. We then jared up the server code, copied the jar and its dependencies to the client project, and listed those jars as dependencies in the client code. We created a module in our NetBeans project called SpringHibernate, which housed those jars, and which almost every other module depended on.

我建议创建一个ant任务,以将jar的版本号删除,然后再将其添加到NetBeans项目中.这使您可以无缝更新服务器代码中的jar,而无需客户机代码知道它们之间的区别. (当您开始删除和重新添加jar时,NetBeans可能会有些挑剔.)

I would recommend creating an ant task that will strip out the version numbers of your jars before adding them to your NetBeans project. This allows you to seamlessly update your jars in the server code without the client code ever knowing the difference. (NetBeans can be kind of picky when you start removing and re-adding jars.)

然后的第一个主要任务是创建一个Util类,该类可以加载applicationContext.xml并从上下文返回bean. 此处概述了该过程.

The first major task then is to create a Util class that can load your applicationContext.xml and return beans from the context. That process is outlined here.

我们遇到的主要障碍之一是创建Sessions(或JPA术语中的EntityManagers). NetBeans平台是一个高度线程化的环境,而EntityManagers设计为只能在单个线程上工作.为了解决这个问题,我们采用了在视图中打开会话"路线*.我们创建了一个类,可以将相同的EntityManager加载到请求它的任何线程中.然后,我们创建了服务的客户端代理,这些代理将在调用实际的Spring托管服务之前将EntityManager加载到其线程中.创建客户端代理服务的另一个好处是,可以通过@ServiceProvider注释在Lookup.getDefault().lookup(Service.class)中找到它们.

One of the major snags that we hit was the creation of Sessions (or EntityManagers in JPA terms). The NetBeans Platform is a highly threaded environment, and EntityManagers are designed to only work on a single thread. To get around this we went with the Open Session In View route*. We created a class that could load the same EntityManager into any thread that requested it. We then created client proxies of our services which would load the EntityManager into its thread before calling the actual Spring-managed service. The added bonus of creating client proxy services was that they were able to be found with Lookup.getDefault().lookup(Service.class) via the @ServiceProvider annotation.

然后,您应该创建一个自定义LifeCycleManager ,它可以拆卸并关闭EntityManager并关闭在应用程序关闭时,EntityManagerFactory.

You then should create a custom LifeCycleManager that can teardown and close your EntityManager and EntityManagerFactory on application shutdown.

我希望这会有所帮助!

**我知道View中的Open Session已经

*I know that Open Session in View has been labeled as an AntiPattern, but as long as you understand the problems associated with it you can mitigate those issues (by caching things objects that are unlikely to change over time, making smart database calls, etc.). Plus, I remember during our research we found a forum post by Gavin King stating that Open Session In View is the recommended route for client applications. Of course, I can't find the post now, but it's out there somewhere.

这篇关于多层企业应用程序中的NBP富客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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