Spring boot + Gradle + Eclipse打war包发布总结

摘要:
没有可以在中发布的项目。也可以在运行后将其移除。我不知道为什么。应该是生成Eclipse web项目的插件。第二个主要是增加对战争方案的支持。第二个是将其更改为在弹簧靴启动器tomcat中提供。提供和编译的区别在于,调试时会加载相应的包,但打包时不会将相应的包添加到war包的lib中,而后者在两种情况下都需要调用相应的包。

首先感谢两位博主的分享

http://lib.csdn.net/article/git/55444?knId=767

https://my.oschina.net/alexnine/blog/540651


buildscript {
    ext {
        springBootVersion = '1.5.2.RELEASE'
    }
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

group 'com.gzkit'
version '1.0.1-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp' apply plugin: 'org.springframework.boot' apply plugin: 'war' compileJava { options.encoding = 'UTF-8' options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } sourceCompatibility = 1.7 targetCompatibility = 1.7 [javadoc, compileTestJava]*.options*.encoding = 'UTF-8' repositories { mavenLocal() maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } jcenter() } configurations { provided //compile.exclude module: "spring-boot-starter-tomcat" //compile.exclude group: 'org.apache.tomcat' //compile.exclude group: 'org.apache.tomcat.embed' all*.exclude module: 'spring-boot-starter-logging' } ext { shiroVersion = '1.3.2' } dependencies { provided('org.springframework.boot:spring-boot-starter-web'){ exclude module: "spring-boot-starter-tomcat" } compile('org.springframework.boot:spring-boot-starter-freemarker') compile('org.springframework.boot:spring-boot-starter-undertow') compile('org.springframework.boot:spring-boot-starter-log4j2') compile('org.springframework.boot:spring-boot-starter-mail') //compile('org.springframework.boot:spring-boot-starter-data-redis') // spring session //compile('org.springframework.session:spring-session') // apache shiro compile("org.apache.shiro:shiro-core:$shiroVersion") compile("org.apache.shiro:shiro-web:$shiroVersion") compile("org.apache.shiro:shiro-spring:$shiroVersion") compile("org.apache.shiro:shiro-ehcache:$shiroVersion") // mybatis support compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1') compile('tk.mybatis:mapper-spring-boot-starter:1.1.1') // apache commons compile('org.apache.commons:commons-lang3:3.4') compile('org.apache.commons:commons-collections4:4.1') // apache poi (excel/word) compile('org.apache.poi:poi:3.14') compile('org.apache.poi:poi-ooxml:3.14') // alibaba datasource runtime('com.alibaba:druid:1.0.27') // mysql jdbc driver runtime('mysql:mysql-connector-java') // log4j2 needs disruptor to enable async logger runtime('com.lmax:disruptor:3.3.5') //compile files('libs/common-uams-2.2.4.jar') testCompile('org.springframework.boot:spring-boot-starter-test') }

两个地方要注意

第一是apply plugin: 'eclipse-wtp',用来生成Eclipseweb项目的插件(web-tool-platform)

  如果不加,在server栏里面的Tomcat上右键,选择Add and Remove…中没有可发布的项目,加上运行后去掉也可以,不知道为啥,应该是已经生成Eclipseweb项目的插件(web-tool-platform)

第二是

  Spring boot + Gradle + Eclipse打war包发布总结第1张

  Spring boot + Gradle + Eclipse打war包发布总结第2张

 主要是添加war包的支持,其次的话就是在spring-boot-starter-tomcat处改为provided。provided和compile的区别在与前者是在调试使用时会加载对应的包,但是 在打包时不会讲对应的包加入到war包的lib中而后者则是两种情况都要调用对应的包。

最后是要修改启动Spring的类

  

public class MonolithicPlatformApplication extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // TODO Auto-generated method stub
        return builder.sources(MonolithicPlatformApplication.class);
    }

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

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return new EmbeddedServletContainerCustomizer() {
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container) {
                // ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
                ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/static/404.html");
                ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/static/500.html");
                container.addErrorPages(error404Page, error500Page);
            }
        };
    }
}

这里继承SpringBootServletInitializer 并重写其中的configure方法目的是使用Spring框架的Servlet3.0支持。并且允许我们可以配置项目从serclet容器中启动。

修改完成之后就可以启动了

另外配上application.yml的配置

server:
    undertow:
        accesslog:
            enabled: true
            dir: target/log
            pattern: combined
    compression:
        enabled: true
        min-response-size: 1
    port: 8080
    session:
        timeout: 1800 # in seconds

spring:
    datasource:
        url: jdbc:mysql://121.201.97.113:3306/km_lis_new?characterEncoding=UTF-8&useSSL=false
        username: root
        password: Zqit3503
        type: com.alibaba.druid.pool.DruidDataSource # 使用druid数据源
        driver-class-name: com.mysql.jdbc.Driver
        maxActive: 2
        initialSize: 1
    redis:
        host: 192.168.1.104
        #password: redispassword
        port: 6379
        pool:
          max-idle: 100
          min-idle: 1
          max-active: 1000
          max-wait: -1
#        database: 0 # database index used by this connection
#        port: 6379
#        host: 192.168.1.104
#        pool:
#            max-active: 30
#            min-idle: 0
#            max-wait: 1500 # milliseconds
#            max-idle: 20
#        timeout: 2000 # connection timeout in milliseconds
    freemarker:
        check-template-location: true
        content-type: text/html
        expose-request-attributes: true
        expose-session-attributes: true
        request-context-attribute: request
        template-loader-path=classpath: /templates/
        settings:
            locale: zh_CN
            template_update_delay: 0
            tag_syntax: auto_detect
            default_encoding: UTF-8
            output_encoding: UTF-8
            url_escaping_charset: UTF-8
            date_format: yyyy-MM-dd
            time_format: HH:mm:ss
            datetime_format: yyyy-MM-dd HH:mm:ss
            number_format: #.##
            classic_compatible: true
            template_exception_handler: rethrow # ignore, debug, html_debug, rethrow
            whitespace_stripping: true
        expose-spring-macro-helpers: true
        suffix: .ftl
        charset: UTF-8
        cache: false
    mvc:
        static-path-pattern: /static/**
    messages:
        basename: i18n/ui_messages
    mail:
        host: smtp.qq.com
        username: 554840442@qq.com
        password: mjevcothmfqybbib #使用QQ邮箱SMTP服务需要生成授权码,而非QQ密码
        sendTo: 554840442@qq.com
        disasterTitle: 手动切换容灾模式
        disasterContent: 会话共享项目-发送邮件功能-手动切换容灾模式~~~~
        normalTitle: 手动切换正常模式
        normalContent: 会话共享项目-发送邮件功能-手动切换正常模式~~~~
        autoTitle: 自动切换运行模式
        autoContent: 会话共享项目-发送邮件功能-自动切换运行模式~~~~
        properties:
            mail:
                smtp:
                    auth: true
                    starttls:
                        enable: true
                        required: true

mybatis:
    config-location: classpath:mybatis-config.xml
    mapper-locations: classpath:mapper/**/*Mapper.xml
    type-aliases-package: com.kmlis.entity

免责声明:文章转载自《Spring boot + Gradle + Eclipse打war包发布总结》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇关于ROS(Robot OS 机器人操作系统)TP3初步了解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

设置Shiro超时时间

1、在shiro的配置文件中配置。 <!-- 会话管理器 --> <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"> <!-- 设置超时时间 --> <prope...

基于OpenAM系列的SSO----基础

基于OpenAM系列的SSO----基础  OpenAM简介:OpenAM是一个开源的访问管理、授权服务平台。由ForegeRock公司发起。OpenAM前身为OpenSSO,由SUN公司创建,现在属于Oracle。 本文在OpenAM 13版的Getting started With OpenAM文档上进行描述和总结。 在这个文档中你将了解如何使...

spring boot服务状态监控+shell远程连接服务

1.在对应服务中引入对应spring boot起步依赖 2.在application.yml中加入对应配置 3.登录相关路径调用相关接口查看服务运行状态 http://localhost:30001/xxx 下表是相关监控接口 4.使用远程ssh工具监控服务状态 控制台中会打印出连接shell的密码,默认用户名:user 在远程连接工具中输入用户...

Hello China操作系统的安装和使用

作为完全自主开发的面向嵌入式应用的操作系统,Hello China目前已发展到V1.75版本。目前具备比较完善的内核、文件系统(FAT32/NTFS)、图形用户界面、网络协议、模块化支持等功能。本文对V1.75在PC下的安装和使用进行描述,以与广大操作系统爱好者做一交流,同时希望能够通过实际应用,对这个操作系统进行测试。 Hello China在Window...

spring学习(三) ———— spring事务操作

     前面一篇博文讲解了什么是AOP。学会了写AOP的实现,但是并没有实际运用起来,这一篇博文就算是对AOP技术应用的进阶把,重点是事务的处理。                                       --wh 一、jdbcTemplate         什么是JdbcTemplate?             spring提供用...

消息队列之 ActiveMQ

简介 ActiveMQ 特点 ActiveMQ 是由 Apache 出品的一款开源消息中间件,旨在为应用程序提供高效、可扩展、稳定、安全的企业级消息通信。 它的设计目标是提供标准的、面向消息的、多语言的应用集成消息通信中间件。ActiveMQ 实现了 JMS 1.1 并提供了很多附加的特性,比如 JMX 管理、主从管理、消息组通信、消息优先级、延迟接收...