0
votes

I'm new to the developing with Spring Boot and React. I'm trying to develop a web based wizard application, with multiple forms. Using Spring Boot as back end and React as front end framework. I want to provide a login form and furthermore multiple forms for the wizard task. Unfortunately I can't manage to make Spring Boot automatically serve my html files to URIs. For example that test.html is displayed on http://localhost:8080/test. So how can I link (React-)html files to Spring Boot's URIs?

I've successfully combined React with Spring Boot so that my index.html with React content is displayed on http://localhost:8080. So the index.html is automatically found and mapped to path '/'. The index.html is in the React folder called public together with other '.html' files. But only the index.html seems to be automatically recognized by Spring Boot. Do I use the wrong folder?

- public
     + index.html
     + login.html
     + publicNoSecurity.html
     + ...
 - src
    + main
     + java
         + com
             * ressources
                 - application.properties
             * webwizard.connection
                 - SelfServiceWebwizard.java
 - index.tsx
 - index.css
 - ...

When I open for example publicNoSecurity, I got 404 Error: no controller -> 404

I also tried to implement a Controller-Class with Requestmappings for the URIs. But this also didn't help:

@Controller
public class DefaultController 
{
    @RequestMapping("/login")
    public String login() {
    return "login";
    }

    @RequestMapping("/publicNoSecurity")
    public String publicNoSecurity() {
    return "publicNoSecurity";
    }
}

With the controller I got the 500 error and a exception: with controller -> 500

2018-07-12 08:35:10.103 ERROR 13560 --- [io-8080-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [publicNoSecurity]: would dispatch back to the current handler URL [/publicNoSecurity] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause

javax.servlet.ServletException: Circular view path [publicNoSecurity]: would dispatch back to the current handler URL [/publicNoSecurity] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.) at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:209) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:147) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) ~[spring-webmvc-5.0.7.RELEASE.jar:5.0.7.RELEASE]

You can see the complete code on github: https://github.com/The-Taskmanager/SelfServiceWebwizard

1

1 Answers

0
votes

Solved by myself. I missed the '.html' in the return value:

@Controller
public class DefaultController 
{
@RequestMapping("/login")
public String login() {
return "login.html";
}

@RequestMapping("/publicNoSecurity")
public String publicNoSecurity() {
return "publicNoSecurity.html";
}
}