REST API-Broadleaf Commerce中的NullPointerException [英] Rest API - NullPointerException in Broadleaf Commerce

查看:85
本文介绍了REST API-Broadleaf Commerce中的NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在搜索框中访问此URL以实现自动填充。.

I am trying to access this url for my autocomplete in the search box..

http://localhost:8080/api/v1/catalog/search/products?q=sauce

但是,我得到了以下内容错误..
似乎在这里

But, I am getting the following error.. It seems here that the

@Resource(name = "blExploitProtectionService")
protected ExploitProtectionService exploitProtectionService;

exploitProtectionService为空

这是错误。.

HTTP ERROR 500

Problem accessing /api/v1/catalog/search/products. Reason:

    Server Error

Caused by:

java.lang.NullPointerException
   at org.broadleafcommerce.core.web.api.endpoint.catalog.CatalogEndpoint.findProductsByQuery(CatalogEndpoint.java:190)
   at com.mycompany.api.endpoint.catalog.CatalogEndpoint.findProductsByQuery(CatalogEndpoint.java:75)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

我的 web.xml 如下

    <servlet>
       <servlet-name>RESTApiServlet</servlet-name>
       <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.mycompany.api.endpoint</param-value>
        </init-param>
   </servlet>

   <servlet-mapping>
       <servlet-name>RESTApiServlet</servlet-name>
       <url-pattern>/api/v1/*</url-pattern>
   </servlet-mapping>

接下来,我的 applicationContext.xml

<context:component-scan base-package="org.broadleafcommerce.core.web.api"/>

applicationContext-security.xml

<!-- Set up Spring security for the RESTful API -->
<sec:http pattern="/api/**" create-session="stateless">
    <sec:http-basic />
    <sec:custom-filter ref="blRestCustomerStateFilter" after="REMEMBER_ME_FILTER"/>
</sec:http>

<!-- Used for REST api calls.   This just takes in the passed in customerId and uses it to establish the customer. -->
<!-- Additional considerations MUST be made for implementations that are allowing external access to APIs. -->
<bean id="blRestCustomerStateFilter" class="org.broadleafcommerce.profile.web.core.security.RestApiCustomerStateFilter"/>

如何解决此问题?如何使 exploitProtectionService 变量不为空。

How to solve this problem? How do I make the exploitProtectionService variable not null. How can it be initialized?

预先感谢。

推荐答案

REST中的搜索功能由solr完成。当您传递q = something时,它将通过solr查询进行搜索。

Search functionality in REST is done by solr. When you pass q="something", then it will be search by solr query.

因此,当您在q中传递*,例如q = *时,它将起作用。但是当您传递q = sauce时,它将不起作用,要使其起作用,必须根据产品名称进行solr索引。

So when you pass * in q like, q=*, then it will work. But when you pass q="sauce", then it won't work, To make it work you have to make solr indexing based on product name.

为此,放在项目核心/src/main/resources/sql/load_catalog_data.sql的sql行上方:

To do so, put above sql lines in your project's core/src/main/resources/sql/load_catalog_data.sql :

INSERT INTO BLC_FIELD (FIELD_ID, ENTITY_TYPE, PROPERTY_NAME, ABBREVIATION, SEARCHABLE, TRANSLATABLE, FACET_FIELD_TYPE) VALUES (1, 'PRODUCT', 'defaultSku.name', 'name', TRUE, TRUE, 's');

INSERT INTO BLC_FIELD_SEARCH_TYPES (FIELD_ID, SEARCHABLE_FIELD_TYPE) VALUES (1, 't');

请确保在执行此行后,可以在数据库的BLC_FIELD和BLC_FIELD_SEARCH_TYPES表中输入条目。

Make sure after executing this lines, you get entry in your DB's BLC_FIELD and BLC_FIELD_SEARCH_TYPES tables.

设置后,您必须修改solr配置。为此,请从site / src / main / resources中打开schema.xml。将默认配置更改为上述行,

After setting this, you have to modify solr configurations. To do so, open schema.xml from site/src/main/resources. Change default configurations to above lines,

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory" />
    <filter class="solr.WordDelimiterFilterFactory"
      generateWordParts="0"
      generateNumberParts="0"
      catenateWords="0"
      catenateNumbers="0"
      catenateAll="0"
      preserveOriginal="1"
      />
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory"/>
      <filter class="solr.PorterStemFilterFactory"/>
      <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="255"/>
    </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.LowerCaseTokenizerFactory" />
    <filter class="solr.WordDelimiterFilterFactory"
      generateWordParts="0"
      generateNumberParts="0"
      catenateWords="0"
      catenateNumbers="0"
      catenateAll="0"
      preserveOriginal="1"
      />
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory"/>
      <filter class="solr.PorterStemFilterFactory"/>
  </analyzer>
</fieldType>

这样做之后,您将能够搜索产品名称,因此当您在内部传递产品名称时q =,那么它将返回您的结果。您可以对制造商,说明等进行相同的操作。

After Doing this, you will be able to search for product name, so when you pass product name inside q="", then it will return you results. You can do the same for manufacturer, description etc...

对于了解solr,此链接将有所帮助。
在阔叶树中进行solr查询

For understanding solr, this link will be helpful. solr query in broadleaf

这篇关于REST API-Broadleaf Commerce中的NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆