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. JAVA实现WC.exe功能

    项目要求 实现一个统计程序,它能正确统计程序文件中的字符数.单词数.行数,以及还具备其他扩展功能,并能够快速地处理多个文件. 具体功能要求: 程序处理用户需求的模式为: wc.exe [paramet ...

  2. 解决Sublime Text 3中文显示乱码和语法着色问题 等问题

    一:解决sublime中文乱码的问题 简单安装: 1.打开Sublime Text 3,按Ctrl+-打开控制行,复制粘贴以下python代码,然后回车运行. 2. 复制并粘贴如下代码: import ...

  3. [leetcode] 16. Add Binary

    这个题目相对有点奇怪,题目如下: Given two binary strings, return their sum (also a binary string). For example, a = ...

  4. linux系统编程之文件与IO(二):系统调用read和write

    read系统调用 一旦有了与一个打开文件描述相连的文件描述符,只要该文件是用O_RDONLY或O_RDWR标志打开的,就可以用read()系统调用从该文件中读取字节 函数原型: #include &l ...

  5. Spring Boot - Spring Data

    使用JPA 虽然JPA是一个标准,但spring中一般就是使用hibernate实现的 使用JPA(Java Persistence API,Java持久化API,是个规范,其实是借助Hibernat ...

  6. 在微信开发中如果WeixinJSBridge.call('closeWindow');关闭窗口无效!

    原因是,成功后页面跳转到普通页面.必须在前面加上 parent.WeixinJSBridge.call('closeWindow'); 这样才行.如果是使用了iframe页面,这样也可以关闭网页,回到 ...

  7. MongoDB下载及安装

    MongoDB的下载及安装 1.下载: MongoDB的官网是:http://www.mongodb.org/ 2.安装: 方案一:(程序启动方式) 1> 创建文件夹:MongoDB    在D ...

  8. EFCore 2.0引用标量函数

    参考文档:https://www.cnblogs.com/CreateMyself/p/8485697.html 1.添加nuget包:EntityFramework.Functions,在上下文类M ...

  9. Restframework 频率throttle组件实例-3

    频率逻辑: from rest_framework.throttling import BaseThrottle import time VISIT_RECORD={} class VisitThro ...

  10. BZOJ 4517--[Sdoi2016]排列计数(乘法逆元)

    4517: [Sdoi2016]排列计数 Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 1727  Solved: 1067 Description ...