Why is Spring not wiring my @Autowired members in a dependent jar?

google-app-engine, ioc-container, java, spring

Solution

I was instantiating my objects incorrectly. For framework objects and such like MVC controllers, you don't need to do anything to get your @Autowired members wired.

For objects I was creating on the fly, I wasn't going through the IOC container, that's why their dependencies weren't being fulfilled.

Problem

I'm building a Google App Engine app using Spring 3.1 and am having a problem getting members in one of my jars wired. I have three projects: - `server` - `server.model` - `server.persistence` I have an ant build script so that when my workspace builds, it creates jars for `server.model` and `server.persistence`, and puts them in the correct lib directory for the `server` project. In `server`, I can autowire things from both `server.model` and `server.persistence`, but in `server.model` my `server.persistence` beans aren't getting wired even though they're the exact same as in `server`. snippet from my servlet application config: ``` <context:component-scan base-package="com.impersonal.server"/> <bean autowire="byType" id="appEngineDataStore" class="com.impersonal.server.persistance.AppEngineDataStore"/> <bean autowire="byType" id="userList" class="com.impersonal.server.model.UserList"/> ``` I have the following code in both the `server` project and the `server.model` project, and only the server one gets fulfilled. Here's the one failing: ``` package com.impersonal.server.model; import java.util.ArrayList; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import com.impersonal.server.persistance.AppEngineDataStore; import com.impersonal.server.persistance.IDataStore; public class UserList extends ArrayList<User> { private UserList(){} //this is always null, but the same line in a class in the other project works private @Autowired AppEngineDataStore _dataStore; public UserList(UUID userId, String tempId) { String poo = "poo"; poo.concat("foo "); int i = 3; } } ``` Edit: Just did a test in the `server.model` project trying to @Autowired something that I don't have defined as a bean in my application config, and didn't get any errors. I should have got a 'no such bean found' error like I do if I do the same thing for the `server` project. Any ideas why?

Original source