多Maven模块Spring MVC项目,以春季启动

在我发布之前,我已经做了大量的研究,并且想要了解是否应该创build一个新的Spring Boot项目,并使用一个多主体结构…或者,我应该转换当前的Maven Spring模块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,我们有一个configuration文件读取外部env.properties文件。

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

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

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

任何帮助,将不胜感激,如果我需要,我可以在这里添加更多的信息,因为我需要。

谢谢!

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

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

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

例如在蜻蜓,你可以做这样的事情:

 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,最后将其复制到部署文件中。