Spring data Solr: IllegalArgumentException — этот аргумент обязателен

Всякий раз, когда я пытаюсь запросить Solr с помощью репозитория данных Spring, я получаю следующее исключение:

Exception in thread "main" java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.util.Assert.notNull(Assert.java:123)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$SolrPropertyValueProvider.readValue(MappingSolrConverter.java:317)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$SolrPropertyValueProvider.readCollection(MappingSolrConverter.java:423)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$SolrPropertyValueProvider.readValue(MappingSolrConverter.java:331)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$SolrPropertyValueProvider.readValue(MappingSolrConverter.java:308)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$SolrPropertyValueProvider.getPropertyValue(MappingSolrConverter.java:294)
    at org.springframework.data.solr.core.convert.MappingSolrConverter.getValue(MappingSolrConverter.java:147)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$1.doWithPersistentProperty(MappingSolrConverter.java:134)
    at org.springframework.data.solr.core.convert.MappingSolrConverter$1.doWithPersistentProperty(MappingSolrConverter.java:126)
    at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:257)
    at org.springframework.data.solr.core.convert.MappingSolrConverter.read(MappingSolrConverter.java:126)
    at org.springframework.data.solr.core.convert.MappingSolrConverter.read(MappingSolrConverter.java:113)
    at org.springframework.data.solr.core.convert.MappingSolrConverter.read(MappingSolrConverter.java:88)
    at org.springframework.data.solr.core.SolrTemplate.convertSolrDocumentListToBeans(SolrTemplate.java:404)
    at org.springframework.data.solr.core.SolrTemplate.convertQueryResponseToBeans(SolrTemplate.java:396)
    at org.springframework.data.solr.core.SolrTemplate.queryForPage(SolrTemplate.java:276)
    at org.springframework.data.solr.repository.query.AbstractSolrQuery$AbstractQueryExecution.executeFind(AbstractSolrQuery.java:312)
    at org.springframework.data.solr.repository.query.AbstractSolrQuery$CollectionExecution.execute(AbstractSolrQuery.java:335)
    at org.springframework.data.solr.repository.query.AbstractSolrQuery.execute(AbstractSolrQuery.java:129)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:323)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at $Proxy15.findByTitleStartingWith(Unknown Source)
    at foo.bar.Application.main(Application.java:46)

Документ:

public class Product {

    @Id
    @Field
    private String id;

    @Field
    private String description;

    @Field
    private String title;

    // getter/setter
} 

Репозиторий:

public interface ProductRepository extends SolrCrudRepository<Product, String> {
    List<Product> findByTitleStartingWith(String title);
}

Конфигурация + тест:

@ComponentScan
@EnableSolrRepositories("foo.bar.repository")
public class Application {

    @Bean
    public SolrServer solrServer() {
        return new HttpSolrServer("http://localhost:8983/solr");
    }

    @Bean
    public SolrTemplate solrTemplate(SolrServer server) throws Exception {
        return new SolrTemplate(server);
    }    

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
        ProductRepository repository = context.getBean(ProductRepository.class);

        Product product = new Product();
        product.setTitle("Foo title");
        product.setDescription("Bar description");
        product.setId(UUID.randomUUID().toString());
        repository.save(product);

        List<Product> list = repository.findByTitleStartingWith("Foo"); // <-- error

        System.out.println("result: " + list);          
    }
}

person micha    schedule 10.11.2013    source источник


Ответы (1)


Я сам нашел решение:

Я использовал конфигурацию поля по умолчанию для Solr (schema.xml). Эта конфигурация включает поля title и description по умолчанию:

<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>

По умолчанию title является полем multiValued. Это вызвало ошибку, когда данные Spring попытались сопоставить поля обратно с моим классом Product.

Удаление multiValued="true" (или установка его на false) из поля title решило проблему.

person micha    schedule 10.11.2013
comment
спасибо за ответ - постараюсь улучшить сообщения об ошибках - person Christoph Strobl; 11.11.2013
comment
Сообщения об ошибках по-прежнему бесполезны в последней версии 1.5.4. - person Turbut Alin; 06.04.2016