Announcement Announcement Module
No announcement yet.
Autowired services are null when not debugging Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowired services are null when not debugging

    I'm attempting to get my application which consists of a couple of beans up and running but I feel like I'm chasing my tail when it comes to getting these services available (for whatever reason when I check in debugging I'm able to get them ... but get null pointer exceptions when I run the methods without a breakpoint!!!?)

    The goal is to have this statistics manager run in the background of the bot collecting and updating data...

    The classes instantiate themselves on their own once defined in the application-context...which I guess is what's supposed to happened.


    I can't figure out how to delete my post! So I'm just going to update this with what I think is the appopriate way to do this with my app. I got it working and no more null pointer exceptions

    Here is the configuration:

             <context:component-scan base-package="" />
             <bean id='tradingBot' class='java.main.example.Bot'>
    		<constructor-arg index="0">
    			<ref bean="simpleTaskExecutor" />
    		<constructor-arg index="1">
    			<ref bean="mtgoxUSD" />
    		<constructor-arg index="2">
    			<ref bean="taskScheduler" />
    I included the bean for Bot because it's where the main application context is loaded.

    public class Bot{
    	public static void main(String[] args) throws Exception {
    		ApplicationContext context = new ClassPathXmlApplicationContext(
                    StatisticsManager manager = new ((StatisticsManager) context.getBean("statisticsManager", StatisticsManager.class));
           // pass any bean instantiations that aren't autowired .. );
    and the class that's giving me trouble:

    class StatisticsManager{
          public TradesService tradeService;
          public void run(// nonauto wired args){
                 taskExecutor.execute((Runnable) new StatisticsManagerRunner(...));
          private class StatisticsManagerRunner implements Runnable(){
                 public void run(){
                         // autowired services should now work
    Last edited by jordanbaucke; Mar 25th, 2013, 11:15 AM.