I have a class similar to this (extraneous code snipped):
I have a spring XML file that includes the following in the beans block:Code:package com.mycompany.myproj; import java.util.List; import com.mycompany.persistence.dao.myStuffDao; import com.mycompany.persistence.model.myStuff; import org.springframework.beans.factory.annotation.Autowired; public class MyThread implements Runnable { @Autowired private MyStuffDao myStuffDao; public void run() { try { List<myStuff> stuffList = (List<myStuff>) myStuffDao.findAll(); // I would do more stuff here, but myStuffDao is null. } catch (Exception e) { log.error("Oops: " + e.getMessage()); } } }
App gets kicked off by Tomcat, which then runs MyThread.Code:<context:component-scan base-package="com.mycompany.myproj"/> <context:annotation-config /> <bean id="app" class="com.mycompany.myproj.App"></bean>
Pretty simple, but at runtime, myStuffDao is null. I've used these persistence classes in a RESTful webapp, and they work fine. This is also in a webapp, but for some reason, Autowiring doesn't occur.
Any tips on where to begin troubleshooting this would be great. I've been trying to get this to work for over a week now. I'm still a Spring amateur, so I'm hoping it's something obvious that I'm missing.


Reply With Quote