我有一个通用的数据访问类:
public class DAO<T extends OrganisationalEntity, TR extends OrganisationalRepository<T>> {
@Autowired OrganisationRepository organisationRepository;
@Autowired TR entityRepository;
...
}
具有一个实体类型(OrganisationalEntity
的子类型和一个存储库类型(OrganisationalRepository<T>
的子类型作为类型参数)。
OrganisationalEntity
是一个接口:
public interface OrganisationalEntity {
Organisation getOrganisation();
void setOrganisation(Organisation organisation);
}
OrganisationalRepository
也是如此,它扩展了JpaRepository
接口:
public interface OrganisationalRepository<T extends OrganisationalEntity>
extends JpaRepository<T, Long> {...}
由此,我尝试为特定数据类型创建数据访问类:
@Component
public class IssueDAO extends DAO<Issue, IssueRepository> {...}
然后在我的控制器中自动连接此数据访问类:
@RestController
@Transactional
class IssueController {
...
@Autowired
IssueDAO issueDAO;
...
}
但这会导致以下错误:
...
Error creating bean with name 'issueDAO'
...
Failed to instantiate [IssueDAO]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Expected 1 type argument on generic interface [DAO<Issue, IssueRepository>] but found 2
...
如果有2个参数,为什么要期待1个参数? 甚至错误消息也列出了2种类型的参数。