snowdrop / spring-data-example

Spring Boot Snowdrop Spring Data Booster
Apache License 2.0
3 stars 5 forks source link

Application Failed To Start with @EnableHibernateSearchRepositories #2

Open agoncal opened 6 years ago

agoncal commented 6 years ago

Hi,

I'm trying to integrate Hibernate Search into a JHipster application, but I'm finding it difficult. I've build your samples, and used them for my application. I've added the following dependency:

    <dependency>
        <groupId>me.snowdrop.data</groupId>
        <artifactId>spring-data-hibernate-search-starter-infinispan</artifactId>
        <version>${spring-boot.hibernate-search.version}</version>
    </dependency>

Then, I just add the @EnableHibernateSearchRepositories annotation to my application, and get the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.zalando.problem.spring.web.advice.security.SecurityProblemSupport required a bean named 'datasourceMapper' that could not be found.
    - Bean method 'createJpaDatasourceMapper' not loaded because @ConditionalOnClass did not find required class 'org.hibernate.search.Search'
    - Bean method 'createInfinispanDatasourceMapper' not loaded because auto-configuration 'HibernateSearchDataInfinispanAutoConfiguration' was excluded

I do not use Infinispan, so I don't get the createInfinispanDatasourceMapper.

Any idea ? Thanks

alesj commented 6 years ago

@agoncal you need to use different starter: https://github.com/snowdrop/spring-data-hibernate-search/blob/master/starters/jpa/pom.xml

(we now have docs which can help you -- see https://github.com/snowdrop/spring-data-hibernate-search/tree/master/documentation/src/main/asciidoc) (pdf / html-single should be in documentation/target after build)

agoncal commented 6 years ago

Thanks @alesj

I've created a simple JHipster app and I'm now trying to add Hibernate Search. If you look at my back-end commit, this is how I tried to configure Hibernate Search.... but it doesn't work. I get the exception below (like if Spring Data was looking for a property called EntityClass).

Following your documentation, I first started to implement RepositoryHibernateSearchExtension, but it didn't work, so I followed your code and ended up implementing HibernateSearchRepository.

Any idea of what I am doing wrong ? Thanks

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property getEntityClass found for type Country!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378)
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:86)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:64)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 104 common frames omitted
alesj commented 6 years ago

@agoncal where are you enabling HS repositories?

alesj commented 6 years ago

@agoncal btw, what was the problem with RepositoryHibernateSearchExtension ? @yrodiere ^^

yrodiere commented 6 years ago

@agoncal I think you're using Spring 4, that's the main issue here. Our module targets Spring Data 2, which is included in Spring 5/Spring Boot 2.

Our tests run against Spring 5.0.0.RELEASE and Spring Boot 2.0.0.M3 at the moment.

agoncal commented 6 years ago

@alesj When I use RepositoryHibernateSearchExtension I get the folllwing:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in org.agoncal.sample.hibsearch.service.CountryService required a bean of type 'org.agoncal.sample.hibsearch.repository.search.CountrySearchRepository' that could not be found.

Action:

Consider defining a bean of type 'org.agoncal.sample.hibsearch.repository.search.CountrySearchRepository' in your configuration.

And I did defined CountrySearchRepository:

@EnableJpaRepositories(value = "org.agoncal.sample.hibsearch.repository",
    basePackages = "org/agoncal/sample/hibsearch/repository",
    basePackageClasses = CountrySearchRepository.class
)

@yrodiere indeed, JHipster usese Spring Boot v1.5.7.RELEASE and Spring v4.3.11.RELEASE. I just tried to upgrade the Spring Boot version to 2.0.0.M3, but it doesn't work :o(

yrodiere commented 6 years ago

And I did defined CountrySearchRepository:

Note that when using Hibernate Search extensions, you must override the the JPA repository factory bean class:

@EnableJpaRepositories(value = "org.agoncal.sample.hibsearch.repository",
    basePackages = "org/agoncal/sample/hibsearch/repository",
    basePackageClasses = CountrySearchRepository.class,
    repositoryFactoryBeanClass =
JpaWithHibernateSearchRepositoryFactoryBean.class // This is important
)

(though obviously it will only work if you use the correct version of Spring Data, see below)

It's all in the documentation, but since you are an early tester the documentation isn't online yet... Here is a PDF I just generated: https://www.docdroid.net/IjC7c0x/hibernate-search-reference.pdf#page=4

I just tried to upgrade the Spring Boot version to 2.0.0.M3, but it doesn't work :o(

@agoncal Do you mean JHipster doesn't work with this version of Spring? In this case you may try to just upgrade the Spring Data dependency. Not sure it will work, since Spring Data 2 may rely on features specific to Spring 5, but it's worth a shot. From what I understood you just need to override the spring-data-releasetrain.version property and set it to Kay-RELEASE.

Or you still have issues with our module (in which case maybe I can help)?