0

I have a microservice app built-in spring boot, the main module is working at 8080 port and the other module is working at 7070 port. At /clicker endpoint I'm trying to redirect to the site which is located on this port but always when I'm using /clicker endpoint I can see an error like this. But when I try to get [http://192.168.254.115:7070] directly from the browser, everything is working fine so I think that's not because of the bad config in the application.properties.

Error resolving template [http://192.168.254.115:7070], template might not exist or might not be accessible by any of the configured Template Resolvers

This controller works at 8080 port.

@CrossOrigin(origins = "*")
public class MainController {

    @RequestMapping("/")
    public String index() {
        return "redirect:/login";
    }

    @RequestMapping("/home")
    public String home(){

        return "home.html";
    }

    @CrossOrigin
    @RequestMapping("/clicker")
    public ModelAndView goToClicker(HttpServletRequest request) {
        //http://localhost:7070/
        //http://192.168.254.115:7070/
        String url = "http://" + request.getServerName() + ":" + "7070";
        return new ModelAndView(url);
    }

}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Home</title>
    <link rel="stylesheet" type="text/css" th:href="@{/styles/style.css}"/>
</head>
<body>
    <div class = "main">
        <div class = "container">

            <button type="button"><a href = "/clicker">CLICKER</a></button>

        </div>
    </div>
</body>
</html>

And that's the controller which works at 7070 port.

@Controller
@CrossOrigin(origins = "*")
public class ClickerController {

    @CrossOrigin
    @RequestMapping("/")
    public String index() {
        return "clicker.html";
    }

}
  • Does this answer your question? [Redirect to an external URL from controller action in Spring MVC](https://stackoverflow.com/questions/17955777/redirect-to-an-external-url-from-controller-action-in-spring-mvc) – Eleftheria Stein-Kousathana Mar 10 '22 at 10:24

0 Answers0