`
yangzb
  • 浏览: 3492227 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Grails and EJB 3 Session Beans

阅读更多

Grails and EJB 3 Session Beans

A while back I was working on a Grails project that needed to integrate with an EJB2 application via session beans. So, when my current project had a similar need I thought 'piece of cake!'. As it happens it was a piece of cake that wasn't that easy to get at.

The problem came about because we were working with EJB3 this time. I had heard that it should work the same but it doesn't. I eventually found that it is still extremely easy to do (this is Grails we're talking about after all) it's just different.

For starters the Spring class that we used to connect to an EJB2 session bean, SimpleRemoteStatelessSessionProxyFactoryBean (I wonder if there is a TinyURL! for class names) was not working with EJB3. Several people on the forums said that it should, but our application did not believe them. It turns out that there is a Spring class that does work with EJB3 and it even has a shorter name! The JndiObjectFactoryBean is a general purpose Factory for looking up JNDI objects and making them available to other beans. The JndiObjectFactoryBean will even use the JndiTemplate that I had setup before, though I'll show it again so you don't have to hunt it down.

So now we should be in business. Except that it didn't work. When using the SimpleRemoteStatelessSessionProxyFactoryBean we could just use the Session Bean's simple interface name, which was also its JNDI name. That was not working with the JndiObjectFactoryBean . This critter wanted a fully qualified, certified and USDA approved JNDI name. The bummer here is that this is vendor specific. So the rest of this will work for BEAORACLE WebLogic but it might be completely different for your app server.

First we have to make sure that the EJB3 session bean has the mappedName attribute in the @Stateless annotation. (In our case ...mappedName="CoverageSession" ) That makes up the first part of the JNDI name. Then we add a # symbol and top it off with the fully qualified name of the Remote Interface. So we ended up with something like this for our JNDI name: CoverageSession#org.blah.app.ejb.session.ICoverageSessionRemote Once we gave it that mouthful it was happy.

Here I'll show a slightly modified version of our resources.groovy file:


beans = {
ejbJndi(org.springframework.jndi.JndiTemplate){
environment = [
  "java.naming.factory.initial" : "weblogic.jndi.WLInitialContextFactory",
  "java.naming.provider.url" : "t3://some.enterprise.server:7001"
  "java.naming.security.principal" : "dave",
  "java.naming.security.credentials" : "1234" ]}

coverageSession(org.springframework.jndi.JndiObjectFactoryBean){
jndiName = "CoverageSession#org.blah.app.ejb.session.ICoverageSessionRemote"
jndiTemplate = ref("ejbJndi")
}
}



Now we can inject the session bean into a Grails Service and we can call its methods to retrieve and save EJB3 entities from that portion of the application that was written before we began using Grails and it all just works and I'm happy!

I'm still hoping to be able to convert the entire application to Grails before we go production but in case we can't the ability to integrate Grails with all of our existing Java technologies is a big help.

分享到:
评论

相关推荐

    grails3-memcached-session:带有grails3的memcached-session-manager的示例

    grails3-memcached-session 这实现了Memcached会话管理器以将会话存储在memcached中。 请注意,memcached会话未写入磁盘,因此重新启动memcached会清除所有会话! 坚持不懈 使用MSM 描述的故障转移策略。 使用...

    grails 开发框架-3

    grails1.0开发框架3 类似于ruby on rails的框架。

    grails3 CAS链接接数据库

    标题中的“grails3 CAS链接接数据库”表明我们要讨论的是如何在Grails 3框架下集成CAS(Central Authentication Service)并实现与数据库的连接。Grails是一个基于Groovy语言的开源Web应用框架,而CAS是一种广泛使用...

    Grails Grails Grails

    3. **插件系统**:Grails 插件是一组可重用的功能模块,可以快速增强应用程序的功能,如Spring Security、Asset Pipeline等。 4. **命令行工具**:Grails 提供强大的命令行工具,支持创建项目、运行应用、生成代码...

    一步一步学grails(3)

    ### Grails 入门教程知识点解析 #### 一、Grails 概述及项目背景 Grails 是一种基于 Groovy 的开源全栈 Web 框架,它利用了 Groovy 和 Java 平台的强大功能来简化 Web 开发过程。本教程以一个实际项目为例,介绍...

    grails 配置mongodb数据库

    在本文中,我们将深入探讨如何在Grails框架中配置MongoDB数据库,并实现用户登录系统。Grails是一款基于Groovy语言的、高效的Web应用开发框架,它借鉴了Ruby on Rails的许多优秀特性。MongoDB则是一种流行的NoSQL...

    Grails权威指南 Grails权威指南

    3. **GORM(Grails Object-Relational Mapping)**:Grails的内置ORM工具,允许开发者以声明式的方式操作数据库,支持SQL的CRUD操作,简化了数据持久化的过程。GORM支持多种数据库,如MySQL、PostgreSQL等。 4. **...

    grails login

    **3. 数据库配置** Grails默认使用H2内存数据库,如需使用MySQL,需修改`Config.groovy`中的数据库配置。添加如下代码: ```groovy dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver" ...

    Eclipse下搭建Grails项目

    3. **安装Groovy Eclipse插件** - Groovy Eclipse插件是Grails在Eclipse中开发的关键,可以从其官方网址(http://groovy.codehaus.org/Eclipse+Plugin)下载。 - 插件安装可以通过Eclipse的Software Update功能或...

    grails-用户手册

    3. Controller:控制器层接收用户请求,调用模型进行业务处理,并决定视图如何显示结果。 三、Grails命令行工具 Grails提供了一套强大的命令行工具,用于快速创建项目、生成控制器、领域类、服务等。例如,`grails...

    Grails 3开发邮件发送功能

    Grails 3版本作为该框架的更新迭代产物,同样支持邮件发送服务。 首先,要在Grails 3中开发邮件发送功能,你需要遵循以下步骤: 1. 新建一个Grails项目。在创建项目的过程中,你需要按照Grails框架的约定设置好...

    eclipse开发grails插件

    3. **配置Grails环境**:安装插件后,需要在Eclipse中配置Grails的路径,这样Eclipse才能找到Grails命令行工具。这通常在"Eclipse Preferences" -> "Grails"中设置。 4. **创建Grails项目**:现在,你可以通过...

    Grails权威指南 中文版

    《Grails权威指南 中文版》是一本专注于Grails框架和Groovy语言的中文版技术书籍。本书的作者是Grails项目负责人Graeme Keith Rocher,他将自己对于Grails框架的深刻理解和使用经验编纂成书,以便向读者全面介绍这一...

    begining groovy and grails

    3. **插件生态系统**:Grails拥有丰富的插件生态系统,这些插件覆盖了从安全性到缓存等各种功能,极大地提升了开发效率。 4. **RESTful Web服务**:Grails支持RESTful Web服务,方便了不同平台间的交互和数据交换。 ...

    grails ajax

    描述中的"javascript and ajax using in grails"强调了JavaScript在Grails应用中的重要性。JavaScript是实现Ajax交互的主要语言,通常用于处理用户交互和动态更新页面。Grails提供了与jQuery等流行JavaScript库集成...

    Grails Persistence with GORM and GSQL

    Grails Persistence with GORM and GSQL

    grails 中文文档+grails-fckeditor-0.9.5.zip插件

    3. Convention over Configuration(CoC):Grails的核心理念之一就是“约定优于配置”,这意味着开发者在很多情况下不需要写大量的配置文件,框架会自动根据约定进行工作。 二、Grails中文文档的价值 1. 学习入口...

    Grails 的过滤器(Grails Filters)

    **Grails 框架与过滤器(Grails Filters)详解** Grails 是一个基于 Groovy 语言的、用于构建动态Web应用的开源框架。它提供了丰富的特性,简化了Java平台上的开发工作,如自动代码生成、元编程支持以及灵活的数据...

Global site tag (gtag.js) - Google Analytics