简体   繁体   中英

Im getting java.lang.StackOverflowError while running my project?

I'm trying to implement solr search with Spring and postgres using maven but on running the appilcation i get 404 with the exception

Exception processing loader WebappLoader[/solrjExample] background process
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.StackOverflowError

I really don't understand what is the problem Here is my spring-servlet:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans=" http://www.springframework.org/schema/beans  "
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:solr="http://www.springframework.org/schema/data/solr"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/data/solr 
   http://www.springframework.org/schema/data/solr/spring-solr.xsd">

    <context:component-scan base-package="org.tcs.com.controller" />
    <context:property-placeholder location="classpath:org/tcs/com/lak/resources/application.properties" />
    <mvc:annotation-driven />
    <bean id="jacksonMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
    <bean
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="html" value="text/html" />
                <entry key="json" value="application/json" />
            </map>
        </property>
        <property name="viewResolvers">
            <list>
                <bean
                    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" 
                        /> -->
                    <property name="prefix" value="/WEB-INF/jsp/" />
                    <property name="suffix" value=".jsp" />
                </bean>
            </list>
        </property>
        <property name="defaultViews">
            <list>
                <bean
                    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
                    <property name="prefixJson" value="true" />
                </bean>
            </list>
        </property>
    </bean>
    <!-- ##################################### SOLR ##################################### -->
    <!-- Configures HTTP Solr server -->
    <solr:solr-server id="solrServer" url="${solr.server.url}" />

    <!-- Configures Solr template -->
    <bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
        <constructor-arg index="0" ref="solrServer" />
    </bean>
<!-- ##################################### postgres ##################################### -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="org.postgresql.Driver"
        p:url="jdbc:postgresql://localhost:5432/Prime" p:username="postgres"
        p:password="Password" /> 
        <!-- ##################################### Hibernate ##################################### -->
    <bean id="sessionfactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:Hibernate.cfg.xml</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">false</prop>
            </props>
        </property>
    </bean> 
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionfactory" />
    </bean>  
</beans>

And my web.xml

<?xml version="1.0" encoding="UTF-8"?>

  <web-app id="WebApp_ID" version="2.4"
   xmlns="http://java.sun.com/xml/ns/j2ee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <display-name>solrjExample</display-name>
   <servlet>
      <servlet-name>solrjExample</servlet-name>
      <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
      </servlet-class>
        <init-param>
       <param-name>contextConfigLocation</param-name>
         <param-value>WEB-INF/slorjExample-servlet.xml</param-value>
       </init-param>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
      <servlet-name>solrjExample</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>

</web-app>

I think there is something wrong with the configuration or something as i am new to solr. Thanks for the help.

The basics behind this error was the use the use of both Solrj and Spring-data-solr it is basically because of the logger used in these API's call each other recursively until the stack overflow error is thrown bring down the tomcat. So i removed the spring-data-solr dependency from my pom.

The purpose of slf4j-jcl module is to delegate or redirect calls made to an SLF4J logger to jakarta commons logging (JCL). 

The purpose of the jcl-over-slf4j module is to redirect calls made to a JCL logger to SLF4J.

 If both slf4j-jcl.jar and jcl-over-slf4j.jar are present on the class path, then a StackOverflowError will inevitably occur immediately after the first invocation of an SLF4J or a JCL logger. 

The problem is described in the link http://www.slf4j.org/legacy.html

Trying to find if there is a workaround for the same.

What do you mean when you say you run your application ? Are you running some sort of searching or you mean when the welcome page is loading ? Is there a specific page you access by default when you run your application ? Did you try and put some debug points in the piece of code which runs when you start up your application ? Or do you mean you get this error when you start your server after deploying your application ?

Generally this kind of error is due to a recursive infinite loop. Do you have some own code executed at server startup ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM