带有spring boot的通用jpa存储库

时间:2018-05-23 16:30:30

标签: spring spring-boot spring-data spring-data-jpa

我正在尝试使用通用的Jpa规范和弹簧启动,但是出现了这个问题。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-23 18:18:27.340 ERROR 1048 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaSpecificationRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object.

在我的代码中我正在尝试使用模块概念,所以我有5个模块(实体,dao,服务,web和frontend with angular)所以这是我的代码:

我的通用Jpa规范界面。

public interface JpaSpecificationRepository<T, ID extends Serializable>
        extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {

}

存储库的例子。

public interface HelloRepository extends JpaSpecificationRepository<Hello, Long> {

}

服务

@Service
public class HelloServiceImpl extends AbstractCRUDService<Hello, Long, HelloDto> {

    @Autowired
    protected HelloServiceImpl(HelloRepository repository, DozerBeanMapper mapper) {
        super(repository, mapper, Hello.class, HelloDto.class);
    }
}

和控制器

@RestController
@CrossOrigin("*")
@RequestMapping("/hello")
public class HelloController extends AbstractCRUDBackOfficeController<Long, HelloDto> {

    @Autowired
    HelloController(HelloServiceImpl service) {
        super(service);
    }
}

1 个答案:

答案 0 :(得分:1)

Text添加到@NoRepositoryBean,以便您可以排除此存储库的实例化。