I'm using annotation-based configuration - no XML at all.
I've configured everything, but can't figure out why OrderService
is not being autowired and continues to be null
. The class below at the very bottom is the one that shows the actual problem. The other classes are all my configuration.
I do have log4j
on this application but am inexperienced with it. Is there a way I can log what packages/classes are being scanned to help determine why this isn't working?
OrderService
@Service
public class OrderService extends GenericService<OrderDAO, Order> {
@Autowired
OrderDAO dao;
}
Services config
@Configuration
public class Config {
@Bean
public OrderService orderService() {
return new OrderService();
}
}
Main Config
@Configuration
@ComponentScan(basePackages = {
"com.production.api",
//todo: may not need the rest of these
"com.production.api.dao",
"com.production.api.models",
"com.production.api.requests",
"com.production.api.requests.job",
"com.production.api.resources",
"com.production.api.resources.job",
"com.production.api.services"
})
@Import({
com.production.api.services.Config.class,
com.production.api.dao.Config.class
})
@PropertySource(value= "classpath:/META-INF/application.properties")
@EnableTransactionManagement
public class Config {
Main.java
public static void main(String[] args) throws IOException {
//process annotation configuration
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
HttpServer httpServer = startServer();
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...", BASE_URI, BASE_URI));
System.in.read();
httpServer.stop();
}
Where the problem is...
@Component
public class NewJobRequestHandler {
public static Logger logger = Logger.getLogger(Logger.class.getName());
//@todo Why isn't this autowiring?
@Autowired
OrderService orderService;
public void instantiateOrderService() {
//@todo remove this manual wiring
orderService = (OrderService) ApplicationContextProvider.getApplicationContext().getBean("orderService");
}
public AuthenticatedApiResponse getResponse(AuthenticatedRequest<NewJobRequest> request) {
instantiateOrderService();