Spring Data JPA custom method causing PropertyRefe

2019-07-18 10:24发布

I have been trying to create a spring boot application. In my application I would like to add some custom methods to save the data instead of using the default save method.

My application entry point is something like this:

@Configuration
@ComponentScan
@EnableJpaRepositories(repositoryImplementationPostfix = "CustomImpl")
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
@PropertySource("application.properties")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);         
    }

}

I have changed this line repositoryImplementationPostfix to even Impl but, it didn't work.

My CrudRepository

@RepositoryRestResource
public interface TaRepository extends CrudRepository<Ta, Integer> ,TestRepository{


    List<Ta> findByName(@Param("name") String name);

}

My Custom Repository:

public interface TestRepository {
    public void myCustomMethod(TestDto dto);
}

My Custom Repository Impl

public class TestRepositoryCustomImpl implements TestRepository{

    @PersistenceContext
    private EntityManager em;
    @Override
    public void myCustomMethod(TestDto model){
}

NOTE:

If I change my CrudRepostory from the mentioned to this:

 @RepositoryRestResource
    public interface TaRepository extends CrudRepository<Ta, Integer> {


        List<Ta> findByName(@Param("name") String name);

    }

everything works fine. But not with the custom method implementation.

1条回答
Emotional °昔
2楼-- · 2019-07-18 11:08

For Spring Data JPA @Repository or @RepositoryRestResource you never need to implement a Custom Interface. For any simple query you can create any kind of method, please follow the simple guide.

http://docs.spring.io/spring-data/jpa/docs/1.4.1.RELEASE/reference/html/jpa.repositories.html

For a complex query you can use JpaSpecificationExecutor.

How can I create a Predicate from a HQL query?

查看更多
登录 后发表回答