2016-05-17 93 views
0

在我發佈之前,我已經做了大量的研究,並且想要了解是否應該創建一個新的Spring Boot項目,並使用多主機結構...或者,我應該將當前的Maven多模塊Spring MVC RESTful項目轉換爲Spring Boot。Multi Maven模塊Spring Spring MVC項目到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 REST風格的後端還使用了Spring配置文件信封,我們有一個配置文件中讀取一個外部env.properties文件。

我們還使用Spring Security 4.0來保護RESTful端點。

我們想把這個應用程序放在Docker容器中嗎?但所有的文檔都可以在Spring Boot中使用,所以我們可以將Spring Boot添加到這個現有的項目中,但我不知道如何...或者從一個新的Spring Boot項目開始,然後以現有的代碼並將其放入新的Spring Boot項目中。我不是哪個更容易,哪個更難?

我們是否還需要Spring Boot將此應用程序放入Docker容器中?

任何幫助將不勝感激,如果我需要,我可以在這裏添加更多的信息,因爲我需要。

謝謝!

回答

2

您不需要Spring Boot將您的應用程序部署在Docker容器中。有幾種策略可以遵循。

下裝到容器(最常用的)二進制

你有你的.war神器部署到關係倉庫。從那裏,從服務器映像開始下載工件,並將其存儲在服務器的部署文件夾中。

例如在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"] 

生成二進制文件的容器(更麻煩):

你可以適應 - 獲取git,簽出一個版本庫分支(master,tag或其他),mvn將其打包生成戰爭並最終將其複製到部署文件中。

+0

感謝您的幫助。 「你可以遵循許多策略......」不幸的是,我不知道這些策略是什麼,以及這些策略的專業/主要是什麼。我一直在試圖找到一個有文件記錄的地方,而且我沒有太多運氣。所以,我會去當地的一些碼頭聚會上嘗試和更多地瞭解Docker。再次感謝您的幫助。 – tjholmes66

相關問題