Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this with AspectJ.</p> <p>Create the @Configurable annotation:</p> <pre><code>@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface Configurable { } </code></pre> <p>Create an AspectJ @Aspect similar to this:</p> <pre><code>@Aspect public class ConfigurableInjectionAspect { private Logger log = Logger.getLogger(getClass().getName()); @Pointcut("@within(Configurable) &amp;&amp; execution(*.new(..)) &amp;&amp; target(instantiated)") public void classToBeInjectedOnInstantiation(Object instantiated) {} @After(value = "classToBeInjectedOnInstantiation(instantiated)", argNames = "instantiated") public void onInstantiation(Object instantiated) { Injector injector = InjectorHolder.getInjector(); if (injector == null) { log.log(Level.WARNING, "Injector not available at this time"); } else { injector.injectMembers(instantiated); } } } </code></pre> <p>Create (and use) a holding class for your injector:</p> <pre><code>public final class InjectorHolder { private static Injector injector; static void setInjector(Injector injector) { InjectorHolder.injector = injector; } public static Injector getInjector() { return injector; } } </code></pre> <p>Configure META-INF/aop.xml:</p> <pre><code>&lt;aspectj&gt; &lt;weaver options="-verbose"&gt; &lt;include within="baz.domain..*"/&gt; &lt;include within="foo.bar.*"/&gt; &lt;/weaver&gt; &lt;aspects&gt; &lt;aspect name="foo.bar.ConfigurableInjectionAspect"/&gt; &lt;/aspects&gt; &lt;/aspectj&gt; </code></pre> <p>Start your VM with aspectjweaver:</p> <pre><code>-javaagent:lib/aspectjweaver.jar </code></pre> <p>Annotate your domain classes:</p> <pre><code>@Entity @Table(name = "Users") @Configurable public class User { private String username; private String nickname; private String emailAddress; @Inject private transient UserRepository userRepository public User() {} } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload