Spring MVC - The Servlet dispatcher encountered an error: java.lang.StackOverflowError

I originally developed an AngularJS + Spring MVC application, named A. I duplicated this web application by copying and pasting the project folder into another one called B.

After running both applications, I noticed they exhibited identical behavior.

My objective is to simplify application A, starting with refactoring the folders containing .html files.

The current folder structure for A is as follows:

src/main/webapp
           |--- WEB-INF/
           |--- META-INF/
           |--- static/
                   |--- js/
                   |--- css/
                   |--- index.html
                   |--- sth.html

The updated folder structure for B looks like this:

src/main/webapp
           |--- META-INF/
           |--- js/
           |--- css/
           |--- index.html
           |--- sth.html

To summarize, I moved all resources from the 'static' folder up a level.

Next, I need to modify the WebMvcConfigurerAdapter in A starting with the old configuration:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "my.package.name")
public class Configurations extends WebMvcConfigurerAdapter {

    // Code here...

}

I plan to create a new WebMvcConfigurerAdapter for B:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "my.package.name")
public class Configurations extends WebMvcConfigurerAdapter {

    // Code here...

}

In essence, I removed the 'static/' prefix from each path.

However, upon running the application, I encountered an Error 500 when requesting 'sth', even though 'index.html' displayed correctly.

GET http://localhost:8080/MyWebApp/sth 500 (Internal Server Error)

Tomcat kept logging a StackOverflowError exception repeatedly.

    SEVERE: Servlet.service() for servlet dispatcher threw exception
    java.lang.StackOverflowError
        at javax.servlet.ServletRequestWrapper.getRemoteAddr(ServletRequestWrapper.java:221)
        at javax.servlet.ServletRequestWrapper.getRemoteAddr(ServletRequestWrapper.java:221)
        at javax.servlet.ServletRequestWrapper.getRemoteAddr(ServletRequestWrapper.java:221)
// More stack trace...

This issue seems related to the controllers and routing within the AngularJS app. Here is an example of the index controller:

@Controller
@RequestMapping("/")
public class IndexController {

    // Code here...

}

Furthermore, the controller responsible for the 'sth' page:

@Controller
public class TemplateController {

    // Code here...

}

The AngularJS router setup within the app.js file:

// Angular code here...

Lastly, the controller handling 'sth' functionality:

// Controller code here...

It appears that there might be something crucial missing, possibly due to front-end structural issues or configuration oversights. My limited experience with AngularJS and Spring MVC makes it challenging to identify the root cause of the problem.

Answer №1

To ensure that the string you return can be resolved into a View by the ViewResolver, consider using the following approach to prevent an infinite loop:

@RequestMapping(value = "/example")
public String displayContent() {
    return "somethingElse";
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the solution for integrating formwizard with steps inside directives using Angular UI and jQuery passthrough?

After successfully implementing the jquery passthrough in angular using the form wizard, I've encountered a new issue. It seems that the jquery passthrough doesn't function properly when the steps within the formwizard are encapsulated inside dir ...

The ng-repeat function is not functioning properly when used within an li element to trigger

I have utilized the Dialog service to create a pop-up window. My intention is to display a message to the user in this format: txt = '<ul> <li data-ng-repeat = "eachValue in dummnyList" > {{eachValue | applyFilte ...

Understand how to extract individual elements from a JSON HTTP response

When making an HTTP request to a REST server (JAX-RS), I receive JSON data in response. The JSON structure includes information about movements and edges for different car IDs. To further process this JSON data, I need to convert each item into a Java obj ...

Encountering issue: LineChart is not recognized as a constructor, resulting in failure to display chart on webpage

I am struggling with displaying a chart in my HTML file that should show the details of a specific process from the past few minutes. Whenever I try to initialize the chart using google.charts.load('current', {'packages':['line&apo ...

Step-by-step Guide to Sending API Header Request Using Selenium and Receiving the Response

My task involves automating an API using selenium and TestNG in Java. While I am aware that it's not the recommended practice to automate APIs with selenium code, I have been given this specific task to complete. The scenario is as follows - I need t ...

Choosing the Date Picker in Selenium WebDriver: A Step-by-Step Guide

Currently delving into Selenium WebDriver with a focus on Java. My goal is to navigate through a date picker dropdown and select specific values for date, month, and year. Here is an example of the HTML tag: <dd id="date-element"> <input id="fro ...

Modifying canvas border colors using AngularJS

Currently, I am in the process of learning AngularJS and have developed a website that includes a canvas element. My main objective is to change the border color after clicking on a checkbox. Here is the code snippet for canvas.html : <!DOCTYPE html&g ...

Executing a sudden termination of the Selenium Cucumber test run

When executing Cuke tests using Selenium, certain preconditions in the system are crucial. Each run may consist of one or more Features, with each Feature confirming specific preconditions at the beginning of the run, such as verifying the presence of th ...

The length property cannot be retrieved from an undefined or null reference while executing ctrl.getplaceholder in the ui-select.js file

https://i.stack.imgur.com/lUPm1.png Hey there! I'm currently working on implementing the ui-select angular directive for multiple auto complete. Everything was running smoothly with Angular version 1.2.18, but as soon as I upgraded to Angular 1.5.5, ...

Entryway to a compilation via resolution

Is there a way to verify a specific field from the users collection of the accounts module in Meteor? Consider the following code snippet: $stateProvider.state('myState', { resolve:{ function($q) { if(Meteor.userId()){ retur ...

The duration required to render DOM elements

Trying to determine the best method for measuring the rendering time of DOM elements in a web browser. Any tips? I'm currently developing an application that involves significant DOM manipulation as part of comparing the performance between Angular 1 ...

Alternatives to getElementById in AngularJS

I am currently utilizing the jquery CircularSlider Plugin to implement 4 sliders on a single page. I have customized values for each slider and now I am looking to retrieve the value of each slider using an angularjs Directive. var intensity = $('#i ...

Query params in the component router of Angular 1

Currently, I am working with Angular 1 and the new component router. The $routeConfig that I have set up looks like this: { path: '/list', name: 'ListCmp', component: 'listCmp', useAsDefault: true } I am trying to navigate ...

AngularTS - Using $apply stops the controller from initializing

Every time I launch the application, the angular {{ }} tags remain visible. Removing $scope.$apply eliminates the braces and displays the correct value. I am utilizing Angular with Typescript. Controller: module Application.Controllers { export class Te ...

Received a NullpointerException when attempting to use the SendKeys method in Selenium while utilizing PageFactory and Page Object

I'm facing an issue with my three classes setup. One class is for retrieving elements from the webpage, another one is for performing actions using those elements, and the third one is for test scripts. Whenever I call a function from the test script, ...

Substituting Div containers with elements imported from external files

Imagine I have <div> <div id="stuff"> <!-- stuff --> </div> </div> Could I move the content of <div id="stuff"> into a separate file named stuff.html, and then replace the code above with something simi ...

Having difficulty running my selenium test on the virtual machine

My goal is to execute my Selenium test using selenium grid. To achieve this, I have set up the hub on my local Ubuntu machine and a node on a Centos VM. I ran the following commands: java -jar selenium-server-standalone-3.141.59.jar -role hub (on local ma ...

What is the best method to ensure that Selenium WebDriver waits for an AJAX load to complete before proceeding with any

Is there a way to ensure that Selenium WebDriver waits for an Ajax load before proceeding with any activities? I am automating the process of filling out a form using my script, where I click on a button that opens a new form with some fields prepopulated ...

Jackson does not seem to be registering the @JsonCreator annotation

I am currently working with Jackson 1.4.2 and facing an issue while trying to deserialize unique identifier values (referred to as `code`) that are sent from our UI to Java controllers (Servlets). We have various types (such as `ABCType`, `XYZType`, etc.) ...

Encountering problems with the Mozilla browser when attempting to execute a click action with Selenium

Check out the HTML snippet of a web page: <div class="col-sm-6 col-md-4 col-lg-3"> <section class="product-cell"> <div class="product-cell-inner ribbon-item "> <div class="product-thumb"> <a href="/bath/produc ...