Spring 和 Java EE 的结合 [英] Combining spring and Java EE

查看:31
本文介绍了Spring 和 Java EE 的结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的项目app-uiapp-services 中有两个模块.app-ui 是一个 portlet项目遵循基于 spring 的实现,并且 app-services 有宁静和肥皂服务遵循基于 Java EE 6 的实现.我们希望启用安全性、日志记录和整个模块中的异常处理方面.

We have two modules in our project app-ui and app-services. app-ui is a portlet project follows spring based implementation and app-services has restful and soap services follows Java EE 6 based implementation. We want to enable security, logging and exception handling aspects through out the modules.

我们面临以下问题:

  1. Spring aop 仅适用于 app-ui.在应用服务方面,我们尝试使用 Load-Time编织和弹簧桥接但没有成功,只有在以下情况下才能成功项目中不存在 beans.xml(Java EE 6).
  2. 我们尝试了 Java EE 全局拦截器(放置在 ejb-jar.xml 中),它仅适用于 EJB.因此它在 app-ui 中不起作用.

有没有办法开发 app-ui 和 app-services 的通用方面?

Is there a way to develop aspects common to app-ui and app-services?

推荐答案

直接使用 AspectJ 而不是 Spring 对它的特定支持它应该可以正常工作,这允许开发在 Spring 和 Java EE 中都可以工作的方面.

Using AspectJ directly and not the spring specific support for it it should work OK, this allows to develop aspects that work both in Spring and Java EE.

可以通过三种方式将 AspectJ 方面编织到代码中:

There are three ways to weave the AspectJ aspects into the code:

  • 编译时编织,意味着我们需要有代码

  • compile time weaving, meaning we need to have the code

字节码编织可以用于没有可用代码的第三方 jar

byte code weaving can be used for third party jars for which no code is available

加载时间编织(不是spring 特定支持)可用于在类加载时编织方面,这可能更具侵入性,因为它需要 JVM 范围的代理,并访问服务器启动脚本.

load time weaving (not the spring specific support) can be used to weave the aspects at class loading time, this can be more invasive as it requires a JVM wide agent, and access to the server startup script.

spring支持 LTW 允许以更方便的方式使用 LTW,但它仅适用于 Spring 应用程序,与上面的 LTW 通用机制不同.

The spring support for LTW allows to use LTW in a more convenient way but it only works for spring applications, unlike the LTW general mechanism above.

所以如果直接使用 LTW 太麻烦,字节码编织和编译时编织仍然是有效的选择,尽管会影响构建过程.

So if using LTW directly is too cumbersome, byte code weaving and compile time weaving are still valid options, although with impact on the build process.

这篇关于Spring 和 Java EE 的结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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