gpt4 book ai didi

maven - 多 Maven 模块 Spring MVC 项目到 Spring Boot

转载 作者:行者123 更新时间:2023-12-02 21:26:31 24 4
gpt4 key购买 nike

在我发帖之前我已经做了很多研究,我想就是否应该创建一个新的 Spring Boot 项目,并使用多 maven 结构......或者,我应该转换我当前的 maven多模块 Spring MVC RESTful 项目到 Spring Boot。

我们想要一个 Spring Boot 项目,因为那时使用 Docker 可能更容易。
我们真的希望在 Docker 容器中使用这个 Spring MVC RESTful 后端,但是我们发现的所有示例都涉及使用 Spring Boot 和 Docker。

因此,该项目具有如下结构:

parent pom.xml 
Entity
- basic Spring Project with Hibernate entities
- has a myproject-entity-context.xml as the Spring application context
- has the database and transactions configured in the context
- translates to a JAR file
- has its own pom.xml and can be built independently
DAO
- basic Spring project with Data Access crud Objects
- has it's own myproject-dao-context.xml file
- inherits from the myproject-entity-context.xml
- pulls in the myproject-entity.jar file in the pom.xml
- translates to a JAR file
- has its own pom.xml so this DAO can be built provided the entity.jar is built
- obviously this layer does all the database work
- very much init tested
Service (Business Services)
- basic Spring project with Transactional Business Services
- one business service can call mutltiple DAO's
- has it's own myproject-service-context.xml file
- inherits from the myproject-dao-context.xml
- pulls in the myproject-dao.jar file in the pom.xml
- translates to a JAR file
- has its own pom.xml so this Service can be built, provided the DAO is built first
- obviously this layer does all the business services work
- very much init tested
Web-Services
- basic Spring Web-App project that compiles to WAR
- has all the Controllers which stores all the endpoints
- has it's own myproject-ws-context.xml file
- inherits from the myproject-service-context.xml
- pulls in the myproject-service.jar file in the pom.xml
- translates to a WAR file
- has its own pom.xml so these Web-Services can be built, provided the myproject-service.JAR is built first
- obviously this layer does all RESTful end-points which call 1 business service
- very much init tested

我们的 Spring MVC RESTful 后端也使用 Spring Env Profiles,我们有一个读取外部 env.properties 文件的配置文件。

我们还使用 Spring Security 4.0 来保护 RESTful 端点。

我们想把这个应用程序放在一个 Docker 容器中吗?但是所有文档都适用于 Spring Boot,所以我们可以将 Spring Boot 添加到这个现有项目中,但我不知道如何......或者从一个新的 Spring Boot 项目开始然后使用我现有的代码可能会更容易并将其放入新的 Spring Boot 项目中。我不知道哪个更容易,哪个更难?

我们甚至需要 Spring Boot 将这个应用程序放入 Docker 容器中吗?

任何帮助将不胜感激,如果需要,我可以根据需要在此处添加更多信息。

谢谢!

最佳答案

您不需要 Spring Boot 在 Docker 容器中部署您的应用程序。您可以遵循几种策略。

将二进制文件下载到容器中(最常用的) :

您已将 .war Artifact 部署到一个 nexus 存储库。从那里,从服务器镜像开始,您下载 Artifact ,将其存储在服务器的部署文件夹中。

例如 野蝇你可以这样做:

FROM jboss/wildfly

EXPOSE 8080

RUN curl -H 'Cache-Control: no-cache' -f http://${NEXUS_REPOSITORY_URL}?r=${REPOSITORY}&g=${GROUP_ID}&a=${ARTIFACT}&p=war&v=${VERSION} -o /opt/jboss/wildfly/standalone/deployments/ROOT.war

对于 Tomcat :
FROM tomcat

EXPOSE 8080

RUN curl -H 'Cache-Control: no-cache' -f http://${NEXUS_REPOSITORY_URL}?r=${REPOSITORY}&g=${GROUP_ID}&a=${ARTIFACT}&p=war&v=${VERSION} -o /usr/local/tomcat/webapps/ROOT.war

CMD ["catalina.sh", "run"]

在容器中生成二进制文件(更麻烦):

您可以 apt-get git, checkout 存储库分支(master、tag 或其他),mvn 打包它以生成 war ,最后将其复制到部署文件。

关于maven - 多 Maven 模块 Spring MVC 项目到 Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37278344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com