我正在尝试创建一个spring boot多模块Restful web服务。我的计划是使用Angular JS和HTML页面来使用这个web服务和一个移动应用程序。
我感到困惑的是,如果tomcat是Spring boot RestController,我如何才能在tomcat启动时获得登录页面。
我想在apache中添加超文本标记语言页面,在tomcat中添加RestFul网络服务。
有没有最好的解决方案,让我可以在一个tomcat中使用Webservice和Html
发布于 2017-02-26 20:22:26
您可以从spring-boot提供静态内容,因此不需要额外配置tomcat。
发布于 2017-02-26 21:14:46
归根结底,AngularJS应用程序由一堆HTML和JS文件组成。因为这些都是简单的静态文件,所以您可以使用Spring Boot来提供这些文件。下面是一个极简主义的例子:
Spring boot应用运行器:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}示例REST控制器:
@RestController
public class MyRestController {
@RequestMapping(value = "/api")
public String getSomething() {
return "something";
}
}一个引导angular应用程序的index.html:
<html>
<head>
<script src="/path/to/angular.js"></script>
<script src="myangularapp.js"></script>
</head>
<body>
<div ng-app="myAngularApp"></div>
</body>
</html>其中index.html和myangularapp.js都位于/resources/public中(假设是Maven项目结构)
在运行spring boot应用程序时,可以在http://localhost:8080/index.html上访问Angular应用程序,在http://localhost:8080/api上可以访问REST界面
https://stackoverflow.com/questions/42437063
复制相似问题