Results 1 to 5 of 5

Thread: Inject properties to a class instantiated by job scheduler

  1. #1
    Join Date
    Aug 2006
    Posts
    144

    Question Inject properties to a class instantiated by job scheduler

    I have a class instantiated by a job scheduler (in this case jBoss instantiates the class by calling its constructor). The class contains properties that are beans specified in the context.

    Currently, I populate those beans in the constructor by getting the context from the classpath and calling getBean() on it.

    Instead I would like to populate them via injection or even better by autowiring. Is it possible? If so, can someone point me to an example?

    Thanks

  2. #2
    Join Date
    Jul 2009
    Posts
    10

    Default

    Have you tried @Configurable?

    Mark your class as @Configurable, provide a setters method to the variables you need to inject.

    In the XML file put the following entries –
    <bean class="class instantiated by job scheduler" abstract="true">
    <property name="variable in your scheduler" ref="reference to that var in your xml"/>
    </bean>
    <aop:spring-configured/>

    Then pass this parameter to your JVM -javaagent : pathtothisjar\aspectjweaver-1.6.1.jar

    This worked for me when I had to inject dependencies into Domain objects instantiated by Hibernate.

    Do post a reply if this works for you.

  3. #3
    Join Date
    Aug 2006
    Posts
    144

    Default

    I am not comfortable passing -javaagent : pathtothisjar\aspectjweaver-1.6.1.jar to the JVM... as it might affect the whole server (as I mentioned the scheduler is the jBoss scheduler).

    To make it easier to understand, think of this as a batch job, launched on a schedule, by the JEE application server.

  4. #4
    Join Date
    Jul 2009
    Posts
    10

    Default

    Add this <context:load-time-weaver
    weaver-class="org.jboss.instrument.classloading.JBoss5Loa dTimeWeaver"/> to your xml and change <aop:spring-configured/> to <context:spring-configured/>. May work with certain versions of JBoss. See https://jira.jboss.org/jira/browse/JBSPRING-1 for related issues.

    I have not tried this on an application server, so not sure if this will work.

    This is from Spring Documentation –
    >>>>>
    6.8.4.6.3. WebLogic, OC4J, Resin, GlassFish
    Recent versions of BEA WebLogic (version 10 and above), Oracle Containers for Java EE (OC4J 10.1.3.1 and above) and Resin (3.1 and above) provide a ClassLoader that is capable of local instrumentation. Spring's native LTW leverages such ClassLoaders to enable AspectJ weaving. You can enable LTW by simply activating context:load-time-weaver as described earlier. Specifically, you do not need to modify the launch script to add -javaagentath/to/spring-agent.jar.
    GlassFish provides an instrumentation-capable ClassLoader as well, but only in its EAR environment. For GlassFish web applications, follow the Tomcat setup instructions as outlined above.
    >>>>>>>

  5. #5
    Join Date
    Jul 2009
    Posts
    10

    Default

    Finally got around to trying my solution and it worked. No need to start jboss with -javagagent, just following the steps mentioned https://jira.jboss.org/jira/browse/J...3Aall-tabpanel and was able to inject dependencies into Classes with @Configurable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •