79481

Combining spring and Java EE

Question:

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.

We face the following problems:

<ol><li>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.</li> <li>We tried Java EE global interceptors (placing in ejb-jar.xml), which works only for EJBs. Hence it wont work in app-ui.</li> </ol>

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

Answer1:

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.

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

<ul><li>

compile time weaving, meaning we need to have the code

</li> <li>

<a href="http://www.eclipse.org/aspectj/doc/next/devguide/bytecode-concepts.html" rel="nofollow">byte code weaving</a> can be used for third party jars for which no code is available

</li> <li>

<a href="http://www.eclipse.org/aspectj/doc/next/devguide/ltw-packaging.html" rel="nofollow">load time weaving</a> (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.

</li> </ul>

The <a href="http://docs.spring.io/spring/docs/3.0.0.RC2/reference/html/ch07s08.html#aop-aj-ltw" rel="nofollow">spring support for LTW</a> allows to use LTW in a more convenient way but it only works for spring applications, unlike the LTW general mechanism above.

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.

Recommend

  • Weave external aspect with new pointcut [duplicate]
  • Can't add execution pointcuts to external jar classes with AspectJ. Why?
  • Eclipselink: Difference between static and dynamic weaving
  • External library usage in xcode
  • Cannot import Common Crypto in a Swift framework [duplicate]
  • Swift 'Could not build Obj-C module 'BranchInvite'
  • log all trace info during a debug session in eclipse
  • Exit Spring Integration when no more messages
  • Python 32/64-bit machine float summing of transposed matrix not correct?
  • SDN4 Config - java.lang.annotation.AnnotationFormatError: Invalid default: …EnableNeo4jRepositories.
  • Creating a Bridging Header
  • How to call method on spring proxy once initialised
  • How atomic are mongoengine's operations
  • How to retrieve Business Component rows in SIebel Open UI PM?
  • Listen to the 'change' even of an element in the shadow DOM
  • Sum values in array of hash if they have the same value
  • Create registry key in 32-bit hive on x64 PC using Installshield 2012 LE - Avoid redirection
  • Configuring multiple DefaultJmslistenercontainerfactory
  • JPA flush vs commit
  • Django model inheritance, filtering models
  • Ember.js model to be organised as a tree structure
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • What is the purpose of TaskExecutor in spring?
  • Loading .coffee files via a view in Rails
  • How can I set a binding to a Combox in a UserControl?
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Create DicomImage from scratch using Dcmtk
  • Jackson Parser: ignore deserializing for type mismatch
  • OpenGL ES texture problem, 4 duplicate columns and horizontal lines (Android)
  • Problems to linebreak with an int in JLabel
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • How can I estimate amount of memory left with calling System.gc()?
  • WOWZA + RTMP + HTML5 Playback?
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • How to load view controller without button in storyboard?