Multi Maven模块Spring MVC项目到Spring Boot

时间:2016-05-17 14:00:59

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

在我发布这里之前,我一直在做很多研究,我想知道是否应该创建一个新的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配置文件,我们有一个配置文件可以读入外部env.properties文件。

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

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

我们是否需要Spring Boot才能将此应用程序放入Docker容器中?

我们非常感谢任何帮助,如果需要,我可以根据需要在此处添加更多信息。

谢谢!

1 个答案:

答案 0 :(得分:2)

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

将BINARIES下载到容器(最常用的)

您将.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"]

在集装箱中生成二进制文件(更多CumBERSOME):

你可以apt-get git,checkout一个存储库分支(master,tag或者其他),mvn打包它来生成war并最终将它复制到部署文件。