@Repository
public interface userRepository extends JpaRepository<User, Long> {
}
有很多网站展示了使用JpaRepository
在Spring 4中创建DAO的这种方式。 @Repository
也一样@Component
通过使用操作者new
而组分扫描具有注释@Component
,@Service
等类(使用@Component
扫描注解)创建实例,@Service
等容器内部豆然后容器如何为@Repository
创建实例如上所示,因为它是一个纯粹抽象的接口,我们不能使用new运算符为接口创建实例。@Repository春季4
这不是普通的弹簧,而是Spring Data,具体是Spring Data JPA。 –