1.修改 eureka,zuul,自己的微服务的pom
打包方式
<packaging>warpackaging>
引入依赖
设置打包名称为ROOT,最后打包出来都是ROOT.war,每个微服务部署到不同的tomcat容器中
2.修改 eureka,zuul,自己的微服务启动类,继承SpringBootServletInitializer重写configure方法
@SpringBootApplication
@EnableEurekaServer
public class EurekaDemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(EurekaDemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(EurekaDemoApplication.class);
}
}
3.修改配置文件
eureka,对应端口号为8761的tomcat
server.port=8761
spring.application.name=eureka-server
spring.jmx.default-domain=eureka-server
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
zuul对应端口号为8080的tomcat
server.port=8080
spring.application.name=server-zuul
spring.jmx.default-domain=server-zuul
eureka.client.service-url.defaultZone=http://127.0.0.1:8761/eureka
自己的微服务,对应端口号为8081的tomcat
server.port=8081
spring.application.name=server-custom
spring.jmx.default-domain=server-custom
eureka.client.service-url.defaultZone=http://127.0.0.1:8761/eureka
4.启动三个tomcat 8081/8761/8080, (启动后测试一下是否真正启动了,如何启动多个tomcat,看另一篇博客)
5.执行 mvn clean package ,把自己的微服务都打成ROOT.war名字的war包,依次放到tomcat webapps下,然后访问eureka,服务注册完成后如下
6.通过网关,发一个请求 http://192.168.94.150:8080/server-custom/getTest 访问通了,tomcat部署springcloud war包成功
代码下载地址 http://download.csdn.net/download/u012326462/10204684