我有界面
public interface ServiceImpl {
public List<?> getAll();
}
并拥有bean类
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 defination
<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)}
答案 0 :(得分: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>