如何使用 SpringBoot 自动重装我的应用程序?
2 回答

Spring Boot的配置方式
Spring Boot中遵循了约定优于配置的原则,故我们在构建Spring Boot Application时非常轻松。在实际生产过程中,我们需要针对工程做额外的配置,那么我们该怎么使用额外的配置呢?
Spring Boot允许使用外部化配置,以便我们可以在不同的环境中使用相同的应用程序代码。 这些配置可以使用属性文件,YAML文件,环境变量和命令行参数等来外化配置。 属性值可以使用@Value注释直接注入到bean中,通过Spring的Environment抽象访问或通过@ConfigurationProperties绑定到结构化对象。
Spring Boot使用一个非常特殊的PropertySource顺序,该顺序被设计为允许对值进行明智的重写。 属性按以下顺序考虑:
Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
@TestPropertySource annotations on your tests.
@SpringBootTest#properties annotation attribute on your tests.
Command line arguments.
Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
ServletConfig init parameters.
ServletContext init parameters.
JNDI attributes from java:comp/env.
Java System properties (System.getProperties()).
OS environment variables.
A RandomValuePropertySource that only has properties in random.*.
Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
Application properties outside of your packaged jar (application.properties and YAML variants).
Application properties packaged inside your jar (application.properties and YAML variants).
@PropertySource annotations on your @Configuration classes.
Default properties (specified using SpringApplication.setDefaultProperties).

使用 Spring Boot 开发工具。
把 Spring Boot 开发工具添加进入你的项目是简单的。
把下面的依赖项添加至你的 Spring Boot Project pom.xml 中
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope></dependency>
重启应用程序,然后就可以了。
同样的,如果你想自动装载页面,有可以看看 FiveReload
http://www.logicbig.com/tutorials/spring-framework/spring-boot/boot-live-reload/.
在我测试的时候,发现了 LiveReload 漏洞,如果你测试时也发现了,请一定要告诉我们。
添加回答
举报