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

查看:95
本文介绍了结合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中运行良好.在应用程序服务方面,我们尝试使用加载时间 编织和弹簧搭桥,但没有成功,只有在以下情况下才能成功 该项目中不存在beans.xml(Java EE 6).
  2. 我们尝试了Java EE全局拦截器(放置在ejb-jar.xml中),该拦截器仅适用于EJB. 因此,它将无法在app-ui中工作.
  1. Spring aop works well only in app-ui. In app-services side we tried using Load-Time Weaving and spring-bridging but did not succeed, it works successfully only if beans.xml(Java EE 6) is not present in the project.
  2. We tried Java EE global interceptors (placing in ejb-jar.xml), which works only for EJBs. Hence it wont work in 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

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

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.

弹簧对LTW的支持允许以更方便的方式使用LTW,但它仅适用于弹簧应用,这与上面的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天全站免登陆