sách gpt4 ai đã đi

spring - 无法 Autowiring 字段

In lại 作者:行者123 更新时间:2023-12-02 07:16:16 28 4
mua khóa gpt4 Nike

Tôi đang sử dụngHibernate 4 + Spring MVC 4当我开始 Apache Tomcat Server 8我收到此错误:

Error creating bean with name 'welcome': Injection of autowired dependencies failed;
Could not autowire field: private dao.IRegion controller.welcome.regionI;
No qualifying bean of type [dao.IRegion] 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)}

这是我的 Hibernate 配置,其中包含 :



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">








${hibernate.dialect}



















dao 是我放置 dao 和接口(interface)的包。

我的区域界面dao.IRegion :

public interface IRegion {

List findAll();

}

我的区域 DAO dao.RegionDAO

@Repository
public class RegionDAO implements IRegion < Region > {

@Autowired
private SessionFactory sessionFactory;

@Ghi đè
public List findAll() {

return sessionFactory.getCurrentSession().createQuery("from Region").list();
}

}

我的 Controller

@Controller
public class welcome {

@Autowired
private IRegion regionI;
....

}

我的 servlet 调度程序



xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">













1 Câu trả lời

RegionDao 类型的 bean 永远不会由 Spring IOC 容器创建,因此该 bean 不受 Spring 管理,这使得它无法进行 Autowiring 。 Spring 基本上是说,我在 Controller 中没有任何满足此依赖关系的 bean。

为了让 RegionDao 由 Spring 创建和管理,组件会扫描 hibernate 配置文件中类的包。


这将在 Spring IOC 容器内创建一个 RegionDao 类型的 bean,并使其可用于 Autowiring 。

关于spring - 无法 Autowiring 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24469109/

28 4 0
Bài viết được đề xuất: sql - 在 SQL Server 中动态地将多行合并为多列
Bài viết được đề xuất: sql - 在网络 PC 上找不到 SQL 实例名称
Bài viết được đề xuất: sql-server - SQL Server - 同一页如何被两个进程独占(X)锁定?
Bài viết được đề xuất: sql - 如何选择行和附近的行
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com