0

我有界面

public interface ServiceImpl {
    public List<?> getAll();
}

并有豆类

public class MessageService implements ServiceImpl{
@Autowired
private SessionFactory sessionFactory;

@Override
public List<MessageItem> getAll() {
    List<MessageItem> lst = sessionFactory.getCurrentSession().createQuery("from MessageItem c").list();
    return lst;
}
}

没有创建 Bean....

豆定义

<bean id="messageService" class="ru.apusvao.phone.model.MessageService"/>

例外

org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [ru.apusvao.phone.model.MessageService] 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)}
4

1 回答 1

0
public class MessageService implements ServiceImpl{
@Autowired
@Qualifier("transactionmanager")
private SessionFactory sessionFactory;

@Override
public List<MessageItem> getAll() {
    List<MessageItem> lst = sessionFactory.getCurrentSession().createQuery("from MessageItem c").list();
    return lst;
}
}

 <!-- Hibernate session factory -->
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    ...
</bean>

<!-- Hibernate transaction manager -->
<bean id="transactionManager"
    class="MessageService">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
于 2013-07-24T10:38:13.300 回答