-
2019-05-18 16:05:32
一 概念
外置tomcat:独立安装在电脑上的Tomcat服务器
springboot内置服务器:springboot自己集成tomcat,不用使用外置的tomcat即可运行网站项目二 原理
三 使用
1)修改项目的打包方式
<packaging>war</packaging>
2)在pom.xml中移除内置的tomcat
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring-boot.version}</version> <!-- 移除嵌入式tomcat插件 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
3)由于移除了内置tomcat,所以需要添加Servlet相关的api
<!--tomcat jsp依赖--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
4)在springboot启动类同级目录下创建一个继承SpringBootServletInitializer接口的类
package com.myworld; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.stereotype.Component; @Component public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { // 注意这里要指向原先用main方法执行的Application启动类 return application.sources(WebAppSpringbootApplication.class); } }
经过以上操作即可正常部署自己的项目到外置tomcat中去
更多相关内容 -
【SpringBoot】三、分别在内置服务器和外置服务器开发JSP页面
2020-09-01 16:20:52目录 一、使用内置服务器 1. File->New->Project... 2. Spring Initializr->next 3. war包 4. 勾选web ...二、外置服务器 1. 同上1~4创建web应用 2. 配置pom.xml,不用上面那些依赖了目录
10. 访问路径localhost:8080/index即可
一、使用内置服务器
请注意SpringBoot 2.x的内置tomcat版本为9.x
1. File->New->Project...
2. Spring Initializr->next
没有Spring Initializr的插件找Spring Boot安装重启下就有了
3. war包
4. 勾选web
5. 编写pom.xml文件
<!--内置tomcat对Jsp支持的依赖,用于编译Jsp--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <!-- 开启servlet支持 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency>
注:tomcat-embed-jasper的scope(作用域)值为provided,表示打包的时候不用打包进去,其他设备会提供,如果打包进去会和外部Tomcat提供的jar冲突,导致项目启动失败。
带有.jsp后缀的请求会被servlet容器分发给JspServlet处理,而JspServlet在第一次被调用时使用jsp引擎解析jsp文件,并生成servlet,并注册,随后调用。如果没有配置tomcat-embed-jasper,则JspServlet没有被注册到Servlet容器中,所以请求分发到DispatcherServlet来处理,就访问不到页面了。
使用外置tomcat时,不需要配置上边的依赖,因为这个在tomcat安装目录的lib里引入了,并且conf/web.xml全局注册了。而使用内置tomcat时,需要手动导入,只有导入了,内置tomcat才帮你自动注册JspServet:
TomcatServletWebServerFactory#prepareContext
protected void prepareContext(Host host, ServletContextInitializer[] initializers) { File documentRoot = this.getValidDocumentRoot(); TomcatEmbeddedContext context = new TomcatEmbeddedContext(); if (documentRoot != null) { context.setResources(new TomcatServletWebServerFactory.LoaderHidingResourceRoot(context)); } context.setName(this.getContextPath()); context.setDisplayName(this.getDisplayName()); context.setPath(this.getContextPath()); File docBase = documentRoot != null ? documentRoot : this.createTempDir("tomcat-docbase"); context.setDocBase(docBase.getAbsolutePath()); context.addLifecycleListener(new FixContextListener()); context.setParentClassLoader(this.resourceLoader != null ? this.resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader()); this.resetDefaultLocaleMapping(context); this.addLocaleMappings(context); try { context.setCreateUploadTargets(true); } catch (NoSuchMethodError var8) { } this.configureTldSkipPatterns(context); WebappLoader loader = new WebappLoader(); loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName()); loader.setDelegate(true); context.setLoader(loader); if (this.isRegisterDefaultServlet()) { this.addDefaultServlet(context); } // 是否需要注册JspServlet if (this.shouldRegisterJspServlet()) { this.addJspServlet(context); this.addJasperInitializer(context); } context.addLifecycleListener(new TomcatServletWebServerFactory.StaticResourceConfigurer(context)); ServletContextInitializer[] initializersToUse = this.mergeInitializers(initializers); host.addChild(context); this.configureContext(context, initializersToUse); this.postProcessContext(context); }
6. 创建jsp文件
7. 配置application.properties
spring.mvc.view.prefix=/WEB-INF/pages/ spring.mvc.view.suffix=.jsp
8. 写个控制器
/** * 测试 * * @author ZRH * @version 1.0.0 * @date 2020/8/31 */ @RestController @RequestMapping public class MyController { @GetMapping("/index") public ModelAndView goIndex(ModelAndView modelAndView) { modelAndView.setViewName("index"); return modelAndView; } }
9. 运行入口类
10. 访问路径localhost:8080/index即可
二、外置服务器
1. 同上1~4创建web应用
2. 配置pom.xml,不用上面那些依赖了
<dependencies> <!--web支持--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
3. 配置外部的tomcat
4. 起飞
-
hbuilder外置服务器设置(局域网移动端调试)
2017-07-03 15:54:481、选择浏览器的最后一个... 外置web服务器 ----> 新建 3、外置web服务器名称 ----> 浏览器运行路径 ----> 确定 注意:浏览器运行路径必须和IP4的IP相同,端口好hbuilder默认的为8020 ...1、选择浏览器的最后一个选项(设置web服务器)或者边改边看模式 ----> 设置按钮 ----> 设置web服务器
2、web服务器 ----> 外置web服务器 ----> 新建
3、外置web服务器名称 ----> 浏览器运行路径 ----> 确定
注意:浏览器运行路径必须和IP4的IP相同,端口好hbuilder默认的为8020
4、运行:web服务器 ----> HTML类文件 ----> 选择你刚刚新建的外置服务器地址 ----> 确定
5、运行结果
注意:第三步设置的浏览器URL必须外置设备在一个局域网内。
其他
[我的博客,欢迎交流!](http://rattenking.gitee.io/stone/index.html)
[我的CSDN博客,欢迎交流!](https://blog.csdn.net/m0_38082783)
[微信小程序专栏](https://blog.csdn.net/column/details/18335.html)
[前端笔记专栏](https://blog.csdn.net/column/details/18321.html)
[微信小程序实现部分高德地图功能的DEMO下载](http://download.csdn.net/download/m0_38082783/10244082)
[微信小程序实现MUI的部分效果的DEMO下载](http://download.csdn.net/download/m0_38082783/10196944)
[微信小程序实现MUI的GIT项目地址](https://github.com/Rattenking/WXTUI-DEMO)
[微信小程序实例列表](http://blog.csdn.net/m0_38082783/article/details/78853722)
[前端笔记列表](http://blog.csdn.net/m0_38082783/article/details/79208205)
[游戏列表](http://blog.csdn.net/m0_38082783/article/details/79035621)
-
eclipse内置服务器打不开 但是外置服务器能打开的问题
2020-02-09 14:34:54我实力吐槽这个内置服务器,折磨我一学期,现在终于好了,内置服务器打不开的原因就是是因为我没有把代理服务器关掉 下面是内置服务器的详解 我用#CSDN#这个app发现了有技术含量的博客,小伙伴们求同去《eclipse内置...我实力吐槽eclipse这个内置服务器,刚安装的时候费了好长时间才给安装成功,后来打开eclipse,运行第一个jsp既然内部服务器不好使,后来百度找了好也没有弄好,我就换了一个外部服务器,但是现在终于好了,内置服务器打不开的原因就是是因为我没有把代理服务器关掉
下面如何让内置服务器好使!
一.代理服务器关掉
1首先找到Internet Explorer(以win7系统)
2.点击设置,然后选择Internet选项
3.然后切换到连接选项卡,选择我们的宽带连接,然后点击设置按钮;
然后把代理服务器前面的对号给取消
注意(如果以前已经给取消了,那就打上勾再取消一遍!!!)
4下面就可以运行啦!
下面这个是win10系统代理服务器怎么关掉!
https://wenwen.sogou.com/z/q719467840.htm?rcer=Q9PEmk2kVIvu-wIIl
(win10代理服务器关掉步骤)
二.eclipse切换浏览器!
1.选择window,然后是perferences
2.选择General,选择Web Browser
3.选择Use external web brower,接着选择你喜欢的浏览器(我选择的是谷歌浏览器)你可以选择别的,然后点击应用就可以了
4.成功图示
 HBuilder编辑器 ... -
Builder搭建外置服务器
2017-08-09 15:11:00如何利用HBuilder快速设置外部web服务器来测试移动web HBuilder 关于HBuilder工具的简介:HBuilder是DCloud(数字天堂)推出的一款支持HTML5的Web开发IDE。HBuilder的编写用到了Java、C、... -
IP设置-内置服务器-外置服务器
2017-03-18 15:27:00HBulider 中 运行 -> 设置web服务器 -> 内置服务器将 127.0.0.1 换为局域网的ip,可以在局域网内所有电脑,手机上浏览页面。... 外置服务器 启动AppServe后,127.0.0.1可以连接,局域网ip192.168.1.10也可... -
Hbuilder+phpstudy 配置外置服务器并编写PHP程序测试
2019-03-28 10:54:08Hbuilder配置外置服务器:工具-->首选项 配置PHP外置服务器:我的笔记本ip地址为localhost:80,PHP配置如下 php文件类型选择配置好的外置服务器 用Hbuilder创建项目,注意phpstudy的路径 之后再... -
HBuilder 使用外置 WEB 服务器
2016-08-15 11:30:11选择“外置服务器” -> 点击“新建” -> 输入“名称”和“浏览器运行URL” -> 点击“确定” 选择“WEB服务器” -> 引用刚才的“名称” -> 点击“确定” 选择“在浏览器内... -
外置USB网络打印服务器设置问题全展现
2021-08-04 03:48:39【IT168评测中心】共享打印和网络打印是现阶段应用最广泛的两种的网络打印模式,前者是使用一台电脑作为打印服务器,打印机通过数据线连接至电脑而电脑连接到局域网;后者是以网卡或者打印服务器的形式将打印机直接... -
服务器篇——如何搭建一个属于你的博客
2021-06-26 02:21:34建网站根据需求可以选择服务器或者虚拟主机。很久很久以前,我还是选择虚拟主机的,但是现在还是选择服务器好一点,也方便一点,而且价格也贵不到哪里去,腾讯云现在活动100元一年,自己建个博客绰绰有余了,还可以... -
无线wifi认证服务器参数设置方法是什么
2021-08-01 09:02:16无线wifi有个认证服务器,可以一定程度下保证所有域用户数据安全,那么在家用wifi中怎么设置认证服务器呢。下面是学习啦小编为大家整理的关于无线wifi认证服务器,一起来看看吧!无线wifi认证服务器的方法无线网络上... -
联耀科技 NeDevice系列8~24口外置式串口服务器产品介绍.pdf
2019-10-21 18:19:40联耀科技 NeDevice系列8~24口外置式串口服务器产品介绍pdf,联耀科技 NeDevice系列8~24口外置式串口服务器产品介绍 -
WampServer服务器环境配置
2020-04-05 12:20:10这样就修改了根目录(这样在www下放的网页我们就可以通过服务器localhost来进行访问了) 3.同时维护多个网站(配置虚拟主机) 采用Apache来配置虚拟主机,相当于让Apache同时维护多个网站。 第一步:找到"httpd.conf... -
联耀科技 NeDevice系列1~4口外置式串口服务器产品介绍.pdf
2019-10-21 18:20:17联耀科技 NeDevice系列1~4口外置式串口服务器产品介绍pdf,联耀科技 NeDevice系列1~4口外置式串口服务器产品介绍 -
外置tomcat映射服务器路径以及springboot内置tomcat映射路径配置
2021-08-10 00:34:20外置tomcat映射路径在tomcat里的conf下的server.xml里Host标签下加入其中的docBase就是磁盘映射路径,path为访问路径,比如localhost:8080/report就可以访问到d盘pdf文件夹下的静态文件image.pngspringboot 1.x内置... -
在线安装k3s集群-外置mysql数据库
2020-08-21 22:31:53一、首先准备一个mysql数据库(mysql5.7以下不支持) 假设数据库信息如下: ...二、连接linux服务器,执行如下脚本直接在线安装 我这里测试使用的系统是centos7.6 curl -sfL https://docs.rancher.cn/k3s/k3s-install.s -
SpringBoot中如何使用外置tomcat服务器
2021-02-03 11:53:24文章目录SpringBoot中如何使用外置tomcat服务器1.确保springboot项目的打包方式是war2.引入外部的tomcat依赖坐标3.把外部的tomcat服务器引入到IDEA中4.启动外部tomcat服务器5.配置tomcat服务器的访问接口 SpringBoot... -
由浅入深玩转华为WLAN—12安全认证配置(5)Portal认证,外置Protal服务器TSM对接
2021-11-26 08:51:54这也是安全认证的最后一种方式了,就是AC与外边Protal服务器对接的认证,这里采用的是华为TSM(目前最新的已经改为policy center了),也支持第三方认证服务器,这里只是简单演示下,更多策略的控制跟应用,可以参考... -
实战华为无线 12.安全认证配置(5)外置Protal服务器
2016-12-28 16:18:51实战华为无线 12.安全认证配置(5)Portal认证,外置Protal服务器TSM对接(网页认证) -
如何从零开始配置一台适用于深度学习的GPU服务器?
2021-08-01 01:33:58作者 | 蔡芳芳计算力正在推动人工智能飞速发展,GPU 深度学习可以说点燃了一个全新的人工智能...但诸如“如何选择一款 GPU 来搭建深度学习平台”、“如何从头开始配置自己的 GPU 服务器”之类的问题一直困扰着开发者...