【问题标题】:Multi Maven Module Spring MVC Project to Spring Boot多 Maven 模块 Spring MVC 项目到 Spring Boot
【发布时间】:2016-09-13 16:26:02
【问题描述】:

在我发帖之前我已经做了很多研究,我想就我是否应该创建一个新的 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 容器中吗?

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

谢谢!

【问题讨论】:

    标签: maven spring-mvc spring-security docker spring-boot


    【解决方案1】:

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

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

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

    例如在 Wildfly 中,您可以这样做:

    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,签出一个仓库分支(master,tag 等等),mvn 打包它来生成war,最后把它复制到部署文件中。

    【讨论】:

    • 感谢您的帮助。 “你可以遵循很多策略……”不幸的是,我不知道这些策略是什么,以及这些策略的优缺点是什么。我一直在试图找到一个记录的地方,但我没有太多运气。因此,我将在我所在的地区参加很多 Docker 聚会,以尝试对 Docker 有更多的了解。再次感谢您的帮助。
    猜你喜欢
    • 2015-10-10
    • 2014-06-02
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    相关资源
    最近更新 更多