Spring Boot将WAR文件部署到Tomcat(十一)

Spring Boot教程之二十五: 使用 Tomcat 部署项目 Tomcat 是默认的 Spring Boot 服务器,它可以在同一个应用程序中管理多个应用程序,从而避免在单个应用程序中为每个应用程序进行多次设置。由于这是一个简单的例子,我们只需展示一下调用“geeks-web-services/hello”时显示的内容,Hello Geek,这是一个简单的问候消息,祝您有个美好的一天。在本文中,我们将创建一个简单的 Spring Boot 应用程序,其中我们将使用 Tomcat 服务器部署该应用程序。而且我们的 war 文件也部署在 tomcat 中。 阅读详情

这篇博文主要用于新手学习Spring Boot,同时也记录自己学习的过程…
文章内容主要来源于易百教程

在本文中,将演示如何将Spring Boot WAR文件部署到Tomcat servlet容器中。
对于Spring Boot WAR部署,需要执行三个步骤:

  • 列表内容扩展SpringBootServletInitializer
  • 根据提供标记嵌入式servlet容器。
  • 更新包装为War

测试工具:

  • Spring Boot2.0.3.RELEASE
  • Tomcat 8.5.32
  • Maven 3

注意
在Spring Boot中,具有嵌入服务器解决方案的最终可执行JAR文件可能不适合所有生产环境,特别市部署团队(具有良好的服务器优化和监控技能知识,但缺乏开发经验的团队),他们希望完全控制服务器,并且不能接触代码。

1. 推展SpringBootServletInitializer
使现有的@SpringBootApplication类扩SpringBootServletInitializer

1.1 - 经典Spring Boot JAR部署(更新此文件以支持WAR部署)
SpringBootWebApplication.java文件的内容如下-

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootApplication{
    public static void main(String[] args) throws Exception{
        SpringApplication.run(SpringBootWebApplication.class,args);
    }
}

1.2 Spring Boot WAR部署
SpringBootWebApplication.java文件的内容如下-

package com.th;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;


@SpringBootApplication
public class SpringBootApplication extends SpringBootServletInitializer{

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
        return application.sources(SpringBootWebApplication.class);
    }
    public static void main(String[] args)throws Exception{
        SpringApplication.run(SpringBootWebApplication.class,args);
    }

}
/*@SpringBootApplication
public class SpringBootWebApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootWebApplication.class, args);
    }

}*/

如果要为部署创建了一个额外的SpringBootWebApplication类,请确保告诉Spring Boot要从哪个主类开始启动程序:
在pom.xml文件中增加以下内容指定-

<properties>
      <start-class>com.th.NewSpringBootWebApplicationForWAR</start-class>
</properties>

2. 提供标记嵌入式servlet容器
在pom.xml文件中增加以下内容指定-

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

<!-- marked the embedded servlet container as provided -->
<!-- 打war包时加入此项, 告诉spring-boot tomcat相关jar包用服务器的,不打成jar -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

Scope选项

范围描述
compile(编译范围)compile是默认的范围;如果没有提供一个范围,那该范围的范围就是编译范围。编译范围依赖在所有的classpath中可用,同时它们也会被打包。
provided(以提供范围)provided依赖只有在当JDK或者一个容器已提供该依赖之后才使用。例如,如果你开发了一个web应用,你可能在编译classpath中需要可用的Servlet APT来编译一个servlet,但是你不会想要在打包好的WAR中包含这个Servlet API;这个Servlet API JAR由你的应用服务器或者servlet容器提供。已提供范围的依赖在编译classpath(不是运行时)可用。它们不是传递性的,也不会被打包。
runtime(运行时范围)runtime依赖在运行和测试系统的时候需要,但在编译的时候不需要。比如,你可能在编译的时候只需要JDBC API JAR,而只有在运行的时候才需要JDBC驱动实现。
test(测试范围)test范围依赖在编译和运行时都不需要,它们只有在测试编译和测试运行阶段可用。
system(系统范围)system范围依赖与provided类似,但是你必须显式的提供一个对于本地系统中JAR文件的路径。这么做是为了允许基于本地对象编译,而这些对象是系统类库的一部分。这样的构件应该是一直可用的,Maven也不会在仓库中去寻找它。 如果你将一个依赖范围设置成系统范围,你必须同时提供一个systemPath元素 。注意该范围是不推荐使用的(应该一直尽量去从公共或定制的Maven仓库中引用依赖)。

3. 更新包装为War
在pom.xml文件中增加以下内容指定-

<packaging>war</packaging>

完成,mvn打包并将$project/target/xxx.war复制到Tomcat发布目录进行部署。

4. 完整的Spring Boot WAR+Tomcat部署
4.1 -以Spring Boot Thymeleaf为例,更新它并手动部署到Tomcat。
4.2-更新现有的SpringBootWebApplication并让它扩展SpringBootServletInitializer类。SpringBootWebApplication.java文件的完整代码如下所示-

package com.th;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringBootWebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootWebApplication.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootWebApplication.class, args);
    }

}

4.3 -更新打包,并按提供的标记spring-boot-starter-tomcat。
pom.xml文件的完整代码如下所示-

<?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>

    <artifactId>spring-boot-web-thymeleaf</artifactId>
    <packaging>war</packaging>
    <name>Spring Boot Web Thymeleaf Example</name>
    <description>Spring Boot Web Thymeleaf Example</description>
    <version>1.0</version>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.0.2.RELEASE</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>
        <!-- This is a web application -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Tomcat embedded container -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>

        <!-- Need this to compile JSP, tomcat-embed-jasper version is not working, 
            no idea why -->
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- Optional, test for static content, bootstrap CSS -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>

        <!-- jasper是将jsp转化为jvm 能识别的class.java 文件 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

    </dependencies>
    <build>
       <!-- 打成war之后的项目名称 -->
        <finalName>springboot</finalName>

        <plugins>
            <!-- Package as an executable jar/war -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceExcludes>src/main/resources/**</warSourceExcludes>
                    <warName>springboot</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.4 - application.properties文件的完整内容如下-

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

welcome.message=Hello Nicole Tang

4.5 - 完整的项目目录结构-
这里写图片描述

4.6 -获取Tomcat并部署WAR文件,执行以下命令-

D:\workspace\spring-boot-web-thymeleaf>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring Boot Web Thymeleaf Example 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ spring-boot-web-thymeleaf ---
[INFO] Deleting D:\workspace\spring-boot-web-thymeleaf\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ spring-boot-web-th
ymeleaf ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ spring-boot-web-thymele
af ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to D:\workspace\spring-boot-web-thymeleaf\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ spring-boo
t-web-thymeleaf ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\workspace\spring-boot-web-thymeleaf\src\test
\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ spring-boot-web
-thymeleaf ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ spring-boot-web-thymeleaf --
-
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:3.1.0:war (default-war) @ spring-boot-web-thymeleaf ---
[INFO] Packaging webapp
[INFO] Assembling webapp [spring-boot-web-thymeleaf] in [D:\workspace\spring-boot-web-thym
eleaf\target\springboot]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\workspace\spring-boot-web-thymeleaf\src\main\webapp]
[INFO] Webapp assembled in [468 msecs]
[INFO] Building war: D:\workspace\spring-boot-web-thymeleaf\target\springboot.war
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.3.RELEASE:repackage (default) @ spring-boot-web-th
ymeleaf ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.080 s
[INFO] Finished at: 2018-08-07T15:24:15+08:00
[INFO] Final Memory: 33M/276M
[INFO] ------------------------------------------------------------------------

D:\workspace\spring-boot-web-thymeleaf>

将生成的springboot.war拷贝到Tomcat发布目录下-
这里写图片描述
例如,写本文章时,Tomcat 发布目录使用的是 –
D:\apache-tomcat-8.5.32\webapps
这里写图片描述
现在点击startup.bat,启动 Tomcat,访问:http://localhost:8080/springboot/ ,程序没有错误问题,应该会看到以下结果 –
这里写图片描述
这里写图片描述




相关文章:

Spring Tool Suite 发布 Spring boot 打包好的war 部署到tomcat下面 概述:大家都指导spring boot 打包好的是jar  不是所谓的war ,但是很多时候是都自动化部署到tomcat 的war 下面。所以要设置发布war  1.找到需要打包项目下面的pom 下面,修改jar 为war 包。 &lt;packaging&gt;war&lt;/packaging&gt; &lt;!--第一步: jar 变为war &lt;packaging&gt... 阅读详情

相关推荐

将Spring Boot项目部署到本地Tomcat中

说明 最近在学Spring Boot,SpringBoot项目自带tomcat,现在需要将项目部署到本地的tomcat运行,记录总结下解决方法 正文 要将Spring Boot项目部署到本地的tomcat中,需要改动三个地方: 一 、将jar改为war Spring Boot 项目创建时自动配置打为jar包,要部署到本地,需要改为war包 二、引入servlet依赖 &lt;...

wds的博客 6560

tomcat java 11_Tomcat系列(11)——Tomcat 部署web应用的4种方法

核心内容1.在Tomcat中有四种部署Web应用的方式,分别是:(1)利用Tomcat自动部署(项目直接拷贝OR WAR包拷贝 到webapps下)(2)利用控制台进行部署(tomcat的manager控制台的deploy区域)(3)增加自定义的Web部署文件(%Tomcat_Home%\conf\Catalina\localhost\AppName.xml)(4)手动修改%Tomcat_Home...

weixin_40006779的博客 614

【项目实战】Spring Boot项目在外部tomcat环境下部署(如何基于Spring Boot将项目打包成war包,并且部署到tomcat中)

别人写好的类,并且打包好了,你可以用这些jar包。引入到你的项目中,然后你就可以直接使用这些jar包中的类还有属性了,这类jar包一般放在lib目录下。Java Archive,Java 归档文件,JAR文件(Java Archive)通常包含一个或多个Java类文件和相关资源文件,如图像、声音等。它们主要用于将Java类库、应用程序和插件打包并分发给其他开发人员和使用者。与平台无关的文件格式,它允许将许多文件组合成一个压缩文件。JavaSE程序可以打包成Jar包。

奶爸的编程之路,也就一周冷个三天 2977

springboot源码理解十一、内嵌tomcat原理

默认Servlet容器 切换Servlet容器 内嵌tomcat自动配置原理 tomcat自动配置类 tomcat工厂类 何时被调用 onRefresh() finishRefresh() springboot版本:2.2.9.RELEASE。 默认Servlet容器 springboot默认支持tomcat、jetty、undertow作为底层容器, 一旦引入spring-boot-starter-web模块,就默认使用tomcat。

CaptainCats的博客 652

Spring Boot入门(27):Spring Boot轻松打包部署:制作war包并快速部署

springboot项目如何打成war包及部署?我一文教会你。

**My Coding Family** 3391

Spring Boot应用部署到外部Tomcat容器实战

Spring Boot是一种约定优于配置的Java框架,旨在简化新Spring应用的初始搭建以及开发过程。其最大的优势在于快速开发和独立运行。由于集成了大量的Starter POMs,Spring Boot能够自动配置项目中常用的模块,从而让开发者专注于业务逻辑的开发。

weixin_42527589的博客 1276

Spring Boot中Tomcat配置

在某些情况下,我们可能需要自定义Tomcat的连接器,以满足特定的安全需求或性能优化需求。这时,我们可以通过编写配置类来实现。@Bean// 可以添加其他自定义配置在这个配置类中,我们创建了一个自定义的Tomcat连接器,并将其添加到TomcatServletWebServerFactory中。通过这种方式,我们可以更灵活地控制Tomcat的行为。Tomcat连接器配置详解在Spring Boot项目中配置Tomcat是一个既简单又复杂的过程。

2401_84150811的博客 4089

PCIe 6.0实战指南:从链路训练到信号完整性的避坑手册

本文是一份针对PCIe 6.0硬件工程师的实战避坑指南。文章深入解析了从NRZ到PAM4调制带来的信号完整性挑战,详细拆解了链路训练(LTSSM)的复杂过程与调试方法,并提供了从信道仿真到实验室实测(如使用Keysight示波器进行眼图与误码率分析)的完整信号完整性闭环验证策略,帮助工程师解决高速率下的链路不稳定与降速问题。

weixin_29306875的博客 342

SpringBoot应用启动内置Tomcat的过程分析

Connector启动过程 Connector是Tomcat提供的类。 // 通过此 Connector 开始处理请求 @Override protected void startInternal() throws LifecycleException { // Validate settings before starting if (getPortWithOffset() < 0) { throw new LifecycleException(sm.getStri

JavaEdge全是干货的技术号 3031

基因树构建全流程:从OrthoFinder到iTOL的保姆级教程(附兰科植物案例)

本文提供了一份从OrthoFinder到iTOL的基因树构建全流程保姆级教程。详细解析了利用OrthoFinder构建物种树、IQ-TREE构建无根基因树、Notung进行树调和生根,以及最终在iTOL中实现专业可视化的每一步操作与实战经验,并以兰科植物NB-ARC基因家族为例进行演示,帮助研究者系统掌握基因树分析方法。

tequila的博客 523

特征模理论指导滤波天线设计的优势和方法

本文探讨了特征模理论在滤波天线设计中的应用优势和方法。特征模理论通过分析天线结构的本征模特性,突破了传统经验设计的局限,实现了辐射与滤波功能的一体化设计。文章重点阐述了如何利用模式显著性(MS)和模式加权系数(MWC)来指导辐射零点的产生,揭示了辐射零点形成的物理机制。通过特征模分析,设计师可以明确调控天线结构和馈电系统,优化滤波性能。这种方法为现代多频/宽带滤波天线设计提供了理论依据和实用工具,显著提升了设计效率和性能指标。

qq_64207806的博客 957

Tomcat部署SpringBoot项目

pom.xml 里 加上

weixin_42562567的博客 986

【C++】POCO学习总结(六):线程、线程池、同步

Poco::RunnableAdapter继承自Poco::Runnable,在Poco::RunnableAdapter构造函数中指定了类和方法;Poco::ThreadLocal是线程局部变量,也叫线程局部存储,意思是模版ThreadLocal中填充的变量属于当前线程,该变量对其他线程而言是隔离的,也就是说该变量是当前线程独有的变量。

郭老二 5099

Java 部署:Spring Boot 应用打包成 War 包(部署 Tomcat)

本文详细介绍了如何将Spring Boot应用从JAR包转换为WAR包部署到外部Tomcat服务器的完整流程。文章首先分析了WAR部署在企业环境中的必要性,包括合规要求、资源共享和遗留系统集成等场景。随后通过具体示例,逐步演示了关键改造步骤:修改打包方式为WAR、排除内嵌Tomcat依赖、调整启动类继承SpringBootServletInitializer、配置构建文件,并提供了本地测试和生产部署的实践指南。全文以Maven项目为例,兼顾Gradle配置说明,帮助开发者快速掌握Spring Boot应用的

千淘万漉虽辛苦,吹尽狂沙始到金 2万+

【Python_Zebra斑马打印机编程学习笔记(二)】基于BarTender将btw文件转换为zpl文件

本文介绍如何基于 BarTender 软件将 btw 格式的文件转换为 zpl 格式的文件,有需要的读者可以点赞收藏,也欢迎在评论区进行讨论。

禾戊之昂的博客 3375

【小白深度教程 1.32】手把手教你从多视角图像进行 3D 重建(SfM 算法)

重建的目标是从一组照片中推导场景的几何结构,假设摄像机位置和内部参数是已知的或可以从图像集中猜测。 这是通过使用多个照片,在其中应用运动结构法(Structure from Motion,SfM)来解决像素级对应问题,部分地恢复3D信息来实现的。

2401_87064292的博客 2160

Spring Boot项目通过tomcat部署项目(包含jar包、war包)

本文介绍了SpringBoot项目的两种Tomcat部署方式:1)内置Tomcat打包为Jar,适合快速开发和独立部署;2)外置Tomcat打包为War,适合传统企业环境。详细说明了每种方式的配置步骤,包括pom.xml修改、入口类调整、打包命令等。重点对比了两种方式的优缺点,并提供了部署时的注意事项,如端口配置、依赖管理等。文章还简要介绍了Tomcat的发展历史和核心功能,帮助开发者根据实际需求选择合适的部署方案。

LMS2022223000的博客 1920

手把手教你学 MATLAB 实战训练(6.5):基础实战实例

MATLAB 是一款强大的数学软件,广泛应用于工程计算、信号处理、控制系统设计、图像处理等领域。学习 MATLAB 不仅可以提高你的编程技能,还能帮助你解决实际的数学和工程问题。下面我将通过几个实战训练实例来教你如何使用 MATLAB。

xiaoheshang_123的博客 366

spring boot+maven项目打包成war包部署到tomcat【局域网内访问】

spring boot+maven项目打包成war包部署到tomcat

Be Like 1万+

小龙虾 OpenClaw 权限全攻略:轻松激活 elevated (最新版 OpenClaw 自动化任务降智、无权限、无法执行sudo等系统命令、提升 elevated 权限的解决方案)

升级小龙虾 OpenClaw 后权限不足?elevated 报错?📛 本文教你如何正确配置 OpenClaw 权限💻,让自动化任务顺利执行 🚀

XiaoqiangClub的博客 733

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Spring Boot:WEB项目,以WAR包形式部署到外部tomcat部署

配置步骤: 1、继承SpringBootServletInitializer 外部容器部署的话,就不能依赖于Application的main函数了,而是要以类似于web.xml文件配置的方式来启动Spring应用上下文,此时我们需要在启动类中继承SpringBootServletInitializer并实现configure方法: import org.springframework...

琦彦 3514

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Spring Boot打war包部署Tomcat8.x

Spring boot默认打包方式为jar,生产环境大多数以war包的形式部署于tomcat下,因此需要将默认的打包方式改为war,需要修改两个文件,涉及以下代码: pom.xml 1、修改打包方式 <packaging>war</packaging> 2、引入servlet-api依赖 <dependency> <groupId>javax.s...

大道至简 1668

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

(spring boot)maven 打包war 部署到tomcat

spring boot maven 部署 tomcat

JasonHector的博客 1862

spring boot项目发布war包部署到tomcat

我有个spring boot项目,在intellij idea里运行得好地地,结果发布成war包,部署到tomcat里,报404,死活无法访问。 原因是,代码还少了点东西。在项目的启动类里,需要重载SpringBootServletInitializer.configure。原因是spring boot默认情况下使用了嵌入容器,支持项目的运行。但发布成war包,扔到tomcat里,就没有这个天然支...

左直拳的马桶_日用桶 2690

spring boot maven项目,导出war,部署到tomcat

1.启动类需要继承SpringBootServletInitializer,重写方法configure @ServletComponentScan @SpringBootApplication public class StartApplication extends SpringBootServletInitializer{ public static void main( S...

ZHANGLIZENG的博客 2705

Spring Boot –将WAR文件部署到Tomcat

在本文中,我们将向您展示如何创建Spring Boot传统WAR文件并将其部署到Tomcat Servlet容器。 在Spring Boot中,要创建用于部署的WAR,我们需要3个步骤: 扩展SpringBootServletInitializer 将嵌入式servlet容器标记为已提供。 更新包装以进行战争 经过测试 Spring Boot 2.1.2发布 T...

一名可爱的技术搬运工 285
上一篇: Spring Boot JSP应用实例(十)
下一篇: Spring Boot Hello World(Thymeleaf)示例(十二)
CZ__
博客等级 码龄9年 97粉丝 114原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值