1

I am trying to create a spring boot Multi-module Restful web service. My plan is to use Angular JS and HTML pages to consume this web service along with a mobile app.

I am confused in how can I get the landing page when the tomcat starts if it's a Spring boot RestController.

I was thinking to add HTML pages in apache and RestFul Webservice in tomcat.

Is there any best solution so that I can use Webservice and Html in one tomcat

2
  • 1
    Have you look at Jhipster ? jhipster.github.io It scaffolds you a Spring Boot+AngularJS working app Commented Feb 24, 2017 at 11:37
  • @BiAiB ok, will go through the document Commented Feb 24, 2017 at 12:24

2 Answers 2

1

You can serve your static content from spring-boot, so you do not need to additionally configure tomcat.

spring-boot serving static content

Sign up to request clarification or add additional context in comments.

Comments

1

When it comes down to it, an AngularJS application consists of a bunch of HTML and JS files. Since those are simply static files, you can serve those files with Spring Boot. Here's a minimalistic example:

Spring boot application runner:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

A sample REST controller:

@RestController
public class MyRestController {
    @RequestMapping(value = "/api")
    public String getSomething() {
        return "something";
    }
}

An index.html which bootstraps the angular app:

<html>
<head>
    <script src="/path/to/angular.js"></script>
    <script src="myangularapp.js"></script>
</head>
<body>
    <div ng-app="myAngularApp"></div>
</body>
</html>

Where index.html and myangularapp.js are both located in /resources/public (assuming a Maven project structure)

When running the spring boot application the Angular app is accessible on http://localhost:8080/index.html The REST interface is accessible on http://localhost:8080/api

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.