Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring Boot和Tomcat为前端内容提供服务_Java_Spring Boot_Tomcat_Web Frontend - Fatal编程技术网

Java 使用Spring Boot和Tomcat为前端内容提供服务

Java 使用Spring Boot和Tomcat为前端内容提供服务,java,spring-boot,tomcat,web-frontend,Java,Spring Boot,Tomcat,Web Frontend,我将创建一个非常典型且不需要资源的前端+后端项目,我的一般问题是如何以更好的方式组织它 后端部分提供RESTAPI,这里将使用Java和Spring引导。嵌入Tomcat或部署WAR的问题仍然悬而未决。我宁愿部署一场战争,除非另一种选择对我的情况有好处。对于开发,我使用Eclipse和Maven,最终所有这些都将在RHEL上工作 前端部分是实现访问API的UI的web应用程序。这里我将使用React 大量教程建议使用前端maven插件,通过Spring Boot(在引擎盖下使用node和npm)

我将创建一个非常典型且不需要资源的前端+后端项目,我的一般问题是如何以更好的方式组织它

后端部分提供RESTAPI,这里将使用Java和Spring引导。嵌入Tomcat或部署WAR的问题仍然悬而未决。我宁愿部署一场战争,除非另一种选择对我的情况有好处。对于开发,我使用Eclipse和Maven,最终所有这些都将在RHEL上工作

前端部分是实现访问API的UI的web应用程序。这里我将使用React

大量教程建议使用前端maven插件,通过Spring Boot(在引擎盖下使用node和npm)为前端内容提供服务。这看起来又漂亮又紧凑。因此,我们的web应用程序位于:

http://my.domain:8080/index.html
访问API的网址:

http://my.domain:8080/api/...
但到目前为止,我发现没有人建议在以下位置的默认http端口(80)上运行web应用程序:

我认为这是实际生产的必需品。

还有一些方法可以将呼叫从端口80重定向到8080,但这看起来不是一个棘手的补丁吗? ApacheTomcat本身可以(显然)配置为在端口80上运行,但这对我来说也不太好


那么,有没有一种方法可以将这样一个项目作为一个整体组织起来(最好由Spring Boot和Tomcat管理),而不让它的部分“分散”在不同的独立服务中?

您可以使用“webapp”文件夹和此配置:

@Configuration
public class MvcConfiguration implements WebMvcConfigurer {


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations("/");
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("/index.html");
    }
}

您可以使用“webapp”文件夹和此配置:

@Configuration
public class MvcConfiguration implements WebMvcConfigurer {


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations("/");
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("/index.html");
    }
}

您不希望在没有真正的web服务器代理(如nginx、httpd或haproxy)的情况下在internet上运行生产应用程序。@Strelok通过代理调用是否是一种普遍做法(例如)Apache WebService到实际由Apache Tomcat提供服务的前端?您不希望在没有像nginx、httpd或haproxy这样的真正web服务器代理的情况下在internet上运行生产应用程序。@Strelok通过(例如)Apache WebService到实际由Apache Tomcat提供服务的前端代理调用是一种普遍做法吗?