1, 热部署:

有jrebel的话, 不用了, 不如jre好用

原理: 使用两个classLoad, 一个加载不改变的jar, 另一个加载可更改的jar, 发生改变后, 舍弃可更改的jar重新restart classloader, 由于加载的类少, 所以更快重启(5s以内)

1), 使用 spring-boot:run运行, 但会存在进程未结束

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
<dependencies>
<!--springloaded hot deploy -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2..RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>

然后可以使用spring-boot:run来进行项目运行, 既可以实现热部署了

2), 如果使用run as java.. 需要将spring-loader-1.2.4.RELEASE.jar下载下来,放到项目的lib目录中,然后把IDEA的run参数里VM参数设置为:

-javaagent:.\lib\springloaded-1.2..RELEASE.jar -noverify

3), 新添加的方法没法进行热部署, 所以: 不使用上面的方式, 使用如下方式: 需要eclipse开启 Build Automatically(自动编译)

添加依赖:

<dependency>
<groupId>org.springframework.boot</>
<artifactId>spring-boot-devtools</>
<optional>true</>
<scope>true</>
</>

然后添加spring-boot-plugin插件:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</>
<artifactId>spring-boot-maven-plugin</>
<configuration>
<!-- 如果没有这个, devTools不起作用-->
<fork>true</>
</>
</></>

修改配置文件, 也会生效, 这个比jre好用

新建class也会生效

页面的修改也会生效, 但需要在applicaton.properties中设置  spring.thymeleaf.cache=false 来实现

需要eclipse开启build automatically, 如果设置springApplication.setRegisterShutdownHook(false) 自动重启不起作用

2, 更改端口号: 

在application.properties中:

server.port=

既可以完成修改了

3, 配置ContextPath

嗯, 在application.properties中修改

server.context-path=/spring-boot

就可以通过 http://ip:port/spring-boot来访问项目了

########################################################
###EMBEDDED SERVER CONFIGURATION (ServerProperties)
########################################################
#server.port=
#server.address= # bind to a specific NIC
#server.session-timeout= # session timeout in seconds
#the context path, defaults to '/'
#server.context-path=/spring-boot
#server.servlet-path= # the servlet path, defaults to '/'
#server.tomcat.access-log-pattern= # log pattern of the access log
#server.tomcat.access-log-enabled=false # is access logging enabled
#server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers
#server.tomcat.remote-ip-header=x-forwarded-for
#server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
#server.tomcat.background-processor-delay=; # in seconds
#server.tomcat.max-threads = # number of threads in protocol handler
#server.tomcat.uri-encoding = UTF- # character encoding to use for URL decoding

4, 锁定jdk版本

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

5, 解决springboot的乱码问题

<build>
<plugins>
<!-- main方法运行需要 -->
<!-- 加入热部署插件, spring-boot:run可用 -->
<!-- java可用, 需要下载jar包放在lib下, 然后修改vm参数 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-</jvmArguments>
</configuration>
<dependencies>
<!--springloaded hot deploy -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2..RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin> </plugins>
</build>

6, 打成jar包直接运行

pom.xml中加入:

<!-- 锁定jdk版本 -->
<properties>
<!-- 指定启动类(main方法的位置) -->
<start-class>com.wenbronk.profiles.App</start-class>
<java.version>1.8</java.version>
<!-- 构建编码 -->
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
</properties>

既可以通过

mvn clean package -Dmaven.skip.test=true

打成jar包, 然后通过命令

java -jar xxx.jar 

运行, 否则会报错找不到主类之类的...

7, 打成war包运行,

pom.xml需要添加:

        <!-- 为了构建一个即是可执行的,又能部署到一个外部容器的war文件,你需要标记内嵌容器依赖为"provided" -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

App类需要:

package com.wenbronk.profile;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication
public class App extends SpringBootServletInitializer { /**
* war使用
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(App.class);
} /**
* jar使用
* @param args
* @throws Exception
* @time 2017年5月15日
*/
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
}

或者不在App上继承, 然后同一目录下 新建一个类:

package com.wenbronk;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer; /**
* war包使用
* @author wenbronk
* @Date 下午3:12:13
*/
public class ServletInitializer extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyOneProjecApplication.class);
} }

springboot-3-其他配置的更多相关文章

  1. SpringBoot的自动配置

    1.根据条件来装配bean,SpringBoot的自动配置,根据条件进行自动配置. 首先创建一个接口,如下所示: package com.bie.encoding; /** * * @Descript ...

  2. SpringBoot的自动配置原理

    一.入口 上篇注解@SpringBootApplication简单分析,说到了@SpringBootApplication注解的内部结构, 其中@EnableAutoConfiguration利用En ...

  3. SpringBoot使用Nacos配置中心

    本文介绍SpringBoot如何使用阿里巴巴Nacos做配置中心. 1.Nacos简介 Nacos是阿里巴巴集团开源的一个易于使用的平台,专为动态服务发现,配置和服务管理而设计.它可以帮助您轻松构建云 ...

  4. SpringBoot的Web配置

    重写全局配置 如果springboot提供的springmvc配置不符合要求,则可以通过一个配置类(标有@Configuration注解的类)加上@EnableWebMvc注解来实现完全自己控制的mv ...

  5. springboot系列三、springboot 单元测试、配置访问路径、多个配置文件和多环境配置,项目打包发布

    一.单元测试 生成的demo里面包含spring-boot-starter-test :测试模块,包括JUnit.Hamcrest.Mockito,没有的手动加上. <dependency> ...

  6. 尚硅谷springboot学习23-SpringMVC配置

    1. Spring MVC auto-configuration 以下是SpringBoot对SpringMVC的默认配置:(WebMvcAutoConfiguration) Inclusion of ...

  7. SpringBoot 多环境配置

    转载:https://www.cnblogs.com/gdpuzxs/p/7191436.html 在我们的实际开发中,一般都有三套环境,开发环境,测试环境,生产环境,三套环境的数据库连接配置也有所不 ...

  8. springboot 多环境配置yml或properties

    https://www.cnblogs.com/mr-yang-localhost/p/8971327.html   springboot 多环境配置 https://blog.csdn.net/li ...

  9. 01-项目简介Springboot简介入门配置项目准备

    总体课程主要分为4个阶段课程: ------------------------课程介绍------------------------ 01-项目简介Springboot简介入门配置项目准备02-M ...

  10. Springboot 日志管理配置logback-spring.xml

    几种常见的日志 Log4j:是最早的日志框架,是apach旗下的,可以单独使用,也可配合日志框架JCL使用: Log4j2:apach旗下的关于log4j的升级版: Logback:是基于slf4j接 ...

随机推荐

  1. underscore chain

    //可以在面向对象或者函数的风格下使用Underscore_.map([1, 2, 3], function(n){ return n * 2; }); //一般习惯用这种 _([1, 2, 3]). ...

  2. java web eclipse中项目的加载过程

    java web eclipse中项目的加载过程: Tomcat默认从WEB-INF/目录下加载资源,Eclipse在发布程序的时候,并没有把User Libraries的相关资源拷贝到WEB-INF ...

  3. SSH框架中配置log4j的方法

    SSH框架中使用log4j的方便之处 1. 动态的改变记录级别和策略,即修改log4j.properties,不需要重启Web应用,这需要在web.xml中设置一下.2. 把log文件定在 /WEB- ...

  4. android应用搬家的实现

    android手机上的应用搬家功能,具体的介绍和原理参考: 系统目录及应用搬家的研究 应用搬家的实现 这里主要是作为一个补充,因为上面两篇文章虽然讲的挺好的,但是给出的例子不能直接运行,还是需要一些准 ...

  5. asp.net core mvc 管道之中间件

    asp.net core mvc 管道之中间件 http请求处理管道通过注册中间件来实现各种功能,松耦合并且很灵活 此文简单介绍asp.net core mvc中间件的注册以及运行过程 通过理解中间件 ...

  6. C#图片处理,缩略图制作

    准备参数:图片文件流.文件名 方法:1.先将图片流通过System.Drawing.Image.FromStream方法转成图片对象 2.通过图片对象.GetThumbnailImage方法生成自定义 ...

  7. System.IO.FileLoadException:“混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。”

    解决方案: 在app.config新增如下配置节: <?xml version="1.0"?> <configuration> <startup us ...

  8. 开源且功能强大的C# 扩展方法类库Pure.Ext,包含1000+个拓展方法 (支持.Net Framework和.Net Core)

    先上地址 Github: https://github.com/purestackorg/pure.ext Gitee: https://gitee.com/purestack/pure.ext 扩展 ...

  9. Systemd 服务管理器

    博文链接:http://www.cnblogs.com/zhenghongxin/p/8672199.html 项目中遇到有些脚本需要通过后台进程运行,保证不被异常中断,变成守护进程的第一步,就是把它 ...

  10. KMP Demo

    The key of Kmp is to build a look up table that records the match result of prefix and postfix. Valu ...