Spring Cloud(三) 把Spring Cloud 打成jar包 war包部署到server上

一、前言

怎样把已经开发的spring cloud 项目进行打包部署,其实过程和spring boot 的是一样的。经过摸索之后,才发现其实spring cloud 的每个Project 可以直接打成jar包运行,因为里面自带了tomcat容器。这也是spring cloud 的一大优势。
官方文档:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

二、打成war包部署

  • 更改pom.xml
war
  • 确保内置servlet container 不会干涉发布该war包的servlet container,方案是标记内置servlet container 的依赖为provided

    
    
        org.springframework.boot
        spring-boot-starter-tomcat
        provided
    
    
  • 最后,将打好的war包放到tomcat下即可.

  • 注意:Spring cloud 打成war后部署到tomcat,如果使用application.properties 文件中配置的端口,会出现无法访问项目。查了一些资料发现如下问题。

application.properties中配置的server.port配置的是spring boot内置的tomcat的端口号, 打成war包部署在独立的tomcat上之后, 你配置的server.port是不起作用的.

三、打成jar包

基于上面的那个问题,如果打成jar包之后,使用内置的容器这个问题就完美解决!

  • pom.xml文件--想maven打包成jar,首先一定要有
      
            cyc  
              
                  
                    org.springframework.boot  
                    spring-boot-maven-plugin  
                  
              
          
          
              
                spring-milestone  
                http://repo.spring.io/libs-release  
              
          

这里要注意:finalName打成包后的包名,其余的是maven的打包需要的文件,这里配置就没问题了。
其次是打包。

debug as -> maven build,第一次打包的话会弹出上面的框,在框中填入package 就可以了。

  • 直接在项目的target目录 中把jar包拿出来放到服务器上执行下面的命令
java  -jar  (jar包的包名)cyc.jar

就ok了!!!

你可能感兴趣的:(springcloud,jar包,部署,springboot)