我有一个如下所示的界面
public interface UserManager {
void insertUser(User user);
.......
现在我有一个实现类如下
@Service
public class UserManagerImpl implements UserManager {
@Autowired
private UserDAO userDAO;
在我的控制器中
@Controller
public class ExampleGizmoController {
@Autowired
private UserManager userManager;
UserDAOImpl 是
@Service
public class UserDAOImpl implements UserDAO {
@Autowired
private SessionFactory sessionFactory;
我的 application-context.xml
<context:annotation-config/>
<context:component-scan base-package="com.foo" />
它扫描我所有的包。我已经将它部署为war文件,当部署发生时,userManager属性没有自动连接到ExampleGizmoController,并在tomcat中显示错误,如下所示
Spring-MVC threw load() exception: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.foo.UserManager] found for dependency: expected at least 1 bean
which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
我能够确定自动装配没有发生,即使它是注释驱动的并且组件扫描已打开。为了自动装配工作,我还应该做些什么吗?