A solution to the problem caused by Springboot automatic configuration

Source: Internet
Author: User

As my project needs to be used in the SOLR, I did a bit of SOLR and springboot integration, the results when the project started, the error ... The first line of the error message is as follows:

class path resource [org/springframework/boot/autoconfigure/solr/solrautoconfiguration.  Class]:

Failed to instantiate [Org.apache.solr.client.solrj.SolrClient]:

Nested exception is java.lang.NoSuchMethodError:org.apache.solr.client.solrj.impl.HttpClientUtil.createClient ( Lorg/apache/solr/common/params/solrparams;)
Lorg/apache/http/impl/client/closeablehttpclient;

My pom coordinates related to SOLR are as follows:

<!--SOLR--   <dependency>        <groupId>org.apache.solr</groupId><artifactId> Solr-solrj</artifactid>   </dependency>

My solrclient-related configuration is as follows:

@Configurationpublic class Solrconfig {@Beanpublic httpsolrclient solr () throws Malformedurlexception {Httpsolrclient Server=new httpsolrclient ("HTTP://192.168.200.130:8080/SOLR"); return server;}}

I was depressed, because actually I started this project and didn't use it to SOLR. The classes associated with SOLR are in another application, except that both applications are sub-modules under a parent module, and all coordinates I declare in the parent module. So, the first thing I think about is that there might be a jar package conflict, So I made a lot of attempts such as using SPRING-DATA-SOLR coordinates, or SPRINGBOOT-STARTER-SOLR coordinates, the results found no use, and later I followed the breakpoint, step by step follow the source, found that when the application started, Springboot created a httpsolrclient for me, and this error was made when Springboot created Httpsolrclient. Said to be unable to find the method. However, given that I do not need to use Springboot's auto-create Httpsolrclient feature, after all solrclient we have created and placed in the spring container. So we have to disable Springboot and SOLR-related autoconfiguration. After looking through the Internet, I ended up disabling the corresponding automatic configuration class on the app launch class (according to the error message, the solrautoconfiguration This class

@SpringBootApplication (Exclude=solrautoconfiguration.class) @ImportResource (locations= "Classpath:conf/dubbo.xml ") public class App  extends Springbootservletinitializer {@Overrideprotected Springapplicationbuilder Configure ( Springapplicationbuilder builder) {return builder.sources (app.class);} public static void Main (string[] args) {Springapplication.run (app.class, args);}}

This problem actually tells us that Springboot's automatic configuration is sometimes not omnipotent, in the face of specific situations, if you need to disable certain configurations, on the startup class @springbootapplication The Exclude attribute specifies the automatic configuration class that needs to be excluded .

A solution to the problem caused by Springboot automatic configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.