-
Jul 21st, 2009, 11:34 AM
#1
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
-
Jul 21st, 2009, 11:54 AM
#2
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.
-
Jul 21st, 2009, 12:35 PM
#3
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.
-
Jul 21st, 2009, 03:19 PM
#4
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 -javaagent
ath/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.
>>>>>>>
-
Jul 26th, 2009, 01:34 PM
#5
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
-
Forum Rules