Announcement Announcement Module
Collapse
No announcement yet.
An aspect to introduce common @PostConstruct code Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • An aspect to introduce common @PostConstruct code

    I have a bit of @PostConstruct code that I want in many, many spring objects.

    Is it possible to use an aspect to automatically introduce this code on any spring bean with a particular annotation (say @MyComponent) ?

    To recap:
    - If a spring bean has @MyComponent annotation
    - It should get the following method and code automatically injected:
    @PostConstruct
    public void myComponentStart()
    {
    // common code here
    }
    - Spring should then instantiate the bean itself as normal, but it should see this @PostConstruct and execute it as you would expect it to had the original code been in this class all along

    Is this possible?

  • #2
    You have to use either loadtime or compiletimeweaving. If you want to same code in a lot of other beans why not simply make an abstract super class and have all the other classes extend that... I would first try to solve it without aspects (basically trying to keep it simple) instead of with aspects, adds a lot of complexity to your application.

    Comment

    Working...
    X