Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:34:59+00:00 2026-06-05T04:34:59+00:00

I’m really starting to wrap my head around AOP and really like the idea

  • 0

I’m really starting to wrap my head around AOP and really like the idea of abstracting out cross-cutting concerns and removing it from my core business code. So far I’ve been reading up on AOP Alliance (which I see is the workhorse for Guice and Spring AOP) and AspectJ.

Unfortunately, good, working Java AOP code examples are hard to come by when we are talking about anything more advanced than simple method interception. I keep reading over and over again how major Java EE concepts such as Persistence, Transaction Handling and Messaging can be implemented with AOP, but for the life of me I can’t find any examples of this!

Ultimately speaking, at the end of the day, AOP does just boil down to method interception (unless I’m missing something major here). So if that’s the case, and given the general form of a method interceptor:

// Using AOP Alliance for this example
public class MyInterceptor implements MethodInterceptor {
    public Object invoke(MethodInvocation inv) {
        // Run this code before executing inv.
        preInvocation();

        Object result = inv.proceed();

        // Run this code after executing inv.
        postInvocation();
    }

    // ...
}

Given that as a starting point, can someone please provide concrete code examples for how each of these Java EE concepts can be delegated to AOP via method interception:

  • Persistence/ORM
  • Transaction Handling
  • Messaging

I guess I’m just having difficulty connecting all the dots and seeing the “forest” through the “trees”. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:35:02+00:00Added an answer on June 5, 2026 at 4:35 am

    No idea for persistence and messaging, but for transactions, I can explain. I’ll take the example of Spring.

    You can configure your Spring beans (typically service layer beans) so that every method invoked on those beans will be intercepted by a transactional interceptor. This interceptor typically does the following thing:

    • see if a transaction is already bound to the current thread
    • if not, start a transaction and bind it to the current thread
    • invoke the method
    • if the transaction was started by this method interception and no runtime exception was thrown by the method, commit the transaction
    • if the transaction was started by this method interception and a runtime exception was thrown by the method, rollback the transaction
    • unbind the transaction from the current thread

    With no transactional aspect the transactional methods would have to do something like this:

    try {
        userTransaction.begin();
        executeSomeBusinessCode();
        userTransaction.commit();
    }
    catch (RuntimeException e) {
        userTransaction.rollback();
    }
    

    It’s cumbersome, error-prone, and doesn’t even handle transaction propagation, new transactions, etc.

    With AOP, the body of the method becomes:

    executeSomeBusinessCode();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.