如何在Tomcat 8.5上部署Broadleaf 5.2

问题描述 投票:0回答:2

我正在使用Eclipse(光子)和Broadleaf社区演示项目(site,admin,api和core)。

我已经能够使用嵌入式Eclipse Web服务器在我的本地开发机器上运行site,admin和api,现在我正在尝试将site,admin和api项目部署为运行AWS EC2实例的WAR Tomcat 8.5(JVM 1.7)。

我遵循了Broadleaf文档:

加上许多其他谷歌搜索网站,但没有成功。这和他们都是从2012年到2015年,并参考BL的旧版本(pre-Servlet 3.0)。

我甚至尝试过“web.xml”方法:

由Maven clean / install生成的WAR文件(我也试过“package”)看起来不像我习惯的典型WAR文件:

网站:(ROOT.war)

META-INF
org
WEB-INF

有人可以举例说明如何在Tomcat服务器上将BLC项目部署为WAR吗?

我得到的结果是端口8443上的404或空白页(使用web.xml方法时)。

对于这个相当开放/模糊的问题感到抱歉,但对于BLC 5.2几乎没有这方面的文档,我转向Stack Overflow寻求帮助。

谢谢


SiteApplication

@SpringBootApplication
@EnableAutoConfiguration
public class SiteApplication extends SpringBootServletInitializer {

    @Configuration
    @EnableBroadleafSiteAutoConfiguration
    public static class BroadleafFrameworkConfiguration {}

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SiteApplication.class);
    }

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

}

pom.hml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.mycompany-community</groupId>
        <artifactId>boot-community-demo</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>boot-community-demo-site</artifactId>
    <packaging>war</packaging>

    <name>Community Demo Site</name>
    <description>Web Module For Customized Broadleaf Commerce Site</description>

    <properties>
        <debug.port>8000</debug.port>
    </properties>

    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.mycompany-community</groupId>
            <artifactId>boot-community-demo-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.broadleafcommerce</groupId>
            <artifactId>broadleaf-framework-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.broadleafcommerce</groupId>
            <artifactId>broadleaf-boot-starter-solr</artifactId>
        </dependency>
        <!--
        <dependency>
            <groupId>com.broadleafcommerce</groupId>
            <artifactId>broadleaf-boot-starter-hsql-database</artifactId>
        </dependency>
        -->
        <dependency>
            <groupId>com.broadleafcommerce</groupId>
            <artifactId>broadleaf-boot-starter-database</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>  
        <dependency>
            <groupId>org.broadleafcommerce</groupId>
            <artifactId>broadleaf-thymeleaf3-presentation</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.zhanhb</groupId>
            <artifactId>thymeleaf-layout-dialect</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>        
    </dependencies>

</project>
broadleaf-commerce
2个回答
4
投票

好的,我们想通了。我想分享我们采取的步骤,因为它是来自不同来源(BLC和Spring Boot站点)的步骤/信息的组合。


第1步:BLC代码库

https://github.com/BroadleafCommerce/DemoSite下载源代码

我使用的文件是“DemoSite-develop-5.2.x”。

在IDE可以查看/访问的位置解压缩。


第2步:IDE(本例中为Eclipse)

按照本网站的步骤(几乎是逐字):

https://www.broadleafcommerce.com/docs/core/current/getting-started/ide-setup/eclipse-setup

您现在应该在本地运行site,admin和api,与内部HSQL数据库通信。

  • 管理员:https:// localhost:8444 / admin
  • 站点:https:// localhost:8443 /
  • API:https://localhost:8445 / api / v1 / swagger-ui.html

第3步:更改为MySQL数据库。

我几乎按照这些说明,一步一步(尽管我已经在我的机器上安装了MySQL):

https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/database-configuration/mysql#


第4步:BLC项目代码/ xml更改

一切都从这个链接开始:

https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/deploying-a-.war-file

在哪里找到:

  • 部署.war文件
  • 我的web.xml在哪里?

按照以下87.1中的步骤操作:

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file

基本上:

  • SiteApplication.java中的SpringBootServletInitializer
  • <packaging>war</packaging>
  • pom.xml文件中的“spring-boot-starter-tomcat”行。

然后我创建了一个“web.xml”文件,(虽然我不是100%确定我需要这个,因为我的servlet容器是Servlet 3.1,而BLC文档说所有这个web.xml配置现在都由注释处理)。

https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/using-a-web.xml

基本上:

  • SiteApplication.java中的BroadleafBootServletContextInitializer 你会注意到我们之前添加了“SpringBootServletInitializer”。 现在我们用“BroadleafBootServletContextInitializer”替换“SpringBootServletInitializer”。
  • 添加您可以在页面底部找到的“web.xml”。
  • 不要忘记将“context-param”标签的“param-value”更改为正确的包位置。

第5步:Tomcat更改

您需要的最多(如果不是全部)的另一个链接:

https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/tomcat

/箱

  • 新的“setenv.sh”文件包含: export CATALINA_OPTS="-Xmx1536M -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

/ conf目录

  • context.xml - 取消注释以下行 `<Manager pathname="" />`
  • somenamehere-keystore(需要生成,或者在BLC代码库中获取一个)
  • server.xml - 添加了HTTPS连接器: <Connector SSLEnabled="true" clientAuth="false" keystoreFile="/path/to/server/apache-tomcat-8.5.29/conf/*somenamehere*.keystore" keystorePass="BLCPassword" keyPass="BLCPassword" keystoreType="PKCS12" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLSv1.2"/> Note that I had to add the "keystoreType" attribute due to my keystore being in the PKCS12 format, as opposed to JKS. The "ciphers" attribute was added as I got an exception complaining about the TLS I was using.
  • 的tomcat-users.xml中 Added the following two lines: <role rolename="manager-gui"/> <user username="admin" password="ReallyHardToGuessPW" roles="manager-gui,admin-gui"/> I'm not sure if this step was 100% needed, but it allows me to see the BLC projects within the "manager" app of Tomcat.

/ webapps中

  • 主持人经理和经理应用程序 In the "META-INF" of these apps I commented out both the "Valve" and "Manager" tags in the "Context". This was extracted from this link: https://www.howtoforge.com/tutorial/how-to-install-apache-tomcat-8-5-on-ubuntu-16-04/ (Look at "Step 6") This appears to be the only difference in my earlier attempts in getting this running (pre-cry-for-SO-help), as yesterday and this morning I had already performed all the steps in this post.

第6步:Maven清理并安装

在Eclipse中,在每个Site和Admin项目(“boot-community-site”和“boot-community-admin”)上,右键单击并选择Run As >> Maven clean。一旦完成运行Run As >> Maven install。

现在,在每个项目的“目标”目录中,您应该看到一个WAR文件(站点项目为“ROOT”,Admin项目为“admin”)。


第7步:启动Tomcat服务器

我启动了Tomcat服务器,其中包含常驻应用程序(文档,示例,主机管理器,管理器和ROOT)。然后我将BLC“admin.war”和“ROOT.war”(站点)热部署到Tomcat / webapps目录。

如果这对您不起作用,您可以随时停止Tomcat服务器并将ROOT.war和admin.war文件放在/ webapps目录中。然后启动服务器。

如果一切顺利,请在启动时查看“catalina.out”日志文件,您将看到一个ASCII“Broadleaf Commerce”消息滚动,每个BLC应用程序一次,然后是一堆MySQL Hibernate消息。对于“m5.large”AWS EC2实例,站点和管理员的整个启动时间似乎约为4分钟。

我会想到我错过了什么,但我现在已经在Tomcat 8.5容器上运行了BLC 5.2。

希望它对我的其他人有一些用处与我有同样的问题。


1
投票

非常有用的指南。我想补充一些关于步骤5的一些事情,特别是关于负载平衡器环境中的弹簧安全性。

由于SSL将在前端代理上发生,因此Spring的安全性需要Secure()可能导致无限循环的重定向。

深度herehere对此进行了解释

解决方法是:

在前端代理上安装ssl证书后,在.properties文件中包含以下两个请求标头:

server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto

没有必要从tomcat进行重定向,因此您不必在步骤5中描述的server.xml中包含https连接器。

只需添加这两行

安全=“真”

方案= “HTTPS”

在tomcat的server.xml的默认连接器上

<Connector port="hereisyourdefaultportofyourtomcat" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           secure="true"
           scheme="https" 
           />

请注意:前端代理应发送上述请求标头。在大多数情况下,默认情况下会发生这种情况。检查here

© www.soinside.com 2019 - 2024. All rights reserved.