Spring Cloud 注册中心在tomcat中部署
来源:互联网 发布:淘宝店的名字怎么取名 编辑:程序博客网 时间:2024/05/22 04:50
前言
最近刚刚接触spring boot 和spring cloud,只知道可以直接通过main方法启动服务,一直不会将项目部署到tomcat中,今天学了一下,做个记录备忘.
步骤
pom文件
在pom文件中引入spring-boot-starter-web,然后排除掉内置的tomcat,最后引入javax.servlet-api,修改package为war,详细如下
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>SpringCloudServer</groupId> <artifactId>Spring_Cloud_Server</artifactId> <version>1.0-SNAPSHOT</version> <name>springcloudserver</name> <packaging>war</packaging> <!--spring cloud server 使用时需要注意parent的版本号和dependencies的版本号--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> <relativePath/> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <!--<version>Brixton.SR5</version>--> <version>Dalston.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!--引入spring boot的web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--排除内置的tomcat--> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!--引入 servlet api--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies></project>
主函数启动类
主函数启动类需要继承SpringBootServletInitializer,重写config方法
import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.support.SpringBootServletInitializer;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication@EnableEurekaServerpublic class ServerApplication_First extends SpringBootServletInitializer{ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(ServerApplication_First.class); } public static void main(String[] args) { new SpringApplicationBuilder(ServerApplication_First.class).web(true).run(args); }}
注意:因为把spring boot自带的tomcat排除了,所以无法再使用main主函数启动程序
注意事项
还有诸多需要注意的地方暂未发现,随着个人的学习逐渐完善,目前这篇博客只使用与spring cloud 注册中心的初学者,尝试在tomcat上部署项目,注意举一反三
阅读全文
0 0
- Spring Cloud 注册中心在tomcat中部署
- spring cloud 注册中心
- Spring Cloud 注册中心Eureka
- spring cloud 服务注册中心
- Spring-cloud注册中心 Eureka
- spring cloud之简单注册中心
- Spring Cloud微服务 注册中心
- Spring Cloud 基于eureka 服务注册中心
- Spring Cloud Eureka (注册中心)
- spring cloud之简单注册中心
- spring cloud 注册中心的搭建
- Spring Cloud 注册中心的保护机制
- 使用Spring Cloud搭建服务注册中心
- 【Spring Cloud】Eureka服务注册中心搭建
- spring-cloud 注册中心eureka环境搭建
- Spring cloud 注册中心使用简介
- Spring Cloud 中使用zookeeper作为服务注册中心与配置中心
- spring cloud 配置中心的部署
- 学生信息系统管理—优化
- POJ 1426 Find The Multiple (数字太大,余数代替原数)
- hdu 1212 Least Common Multiple
- LintCode66
- 加快Android studio 编译
- Spring Cloud 注册中心在tomcat中部署
- 2017 Multi-University Training Contest
- LintCode68
- servlet和CGI
- wireshark 实用过滤表达式(针对ip、协议、端口、长度和内容)
- CentOS7安装Java8
- CentOS6.5定制系统iso制作
- sqoop概念和安装部署
- CodeFroces 429B Godsend (模拟)