spring boot
来源:互联网 发布:mac射手影音字幕位置 编辑:程序博客网 时间:2024/04/29 19:48
<dependencyManagement><dependencies><dependency><!-- Import dependency management from Spring Boot --><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.0.0.BUILD-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
We generally recommend that you locate your main application class in a root package above other classes. The @EnableAutoConfiguration
annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. For example, if you are writing a JPA application, the package of the@EnableAutoConfiguration
annotated class will be used to search for @Entity
items.
Using a root package also allows the @ComponentScan
annotation to be used without needing to specify a basePackage
attribute. You can also use the@SpringBootApplication
annotation if your main class is in the root package.
If you structure your code as suggested above (locating your application class in a root package), you can add @ComponentScan
without any arguments. All of your application components (@Component
, @Service
, @Repository
, @Controller
etc.) will be automatically registered as Spring Beans.
4、隐式的一些参数之类的
- Java 1.8 as the default compiler level.
- UTF-8 source encoding.
- A Dependency Management section, allowing you to omit
<version>
tags for common dependencies, inherited from thespring-boot-dependencies
POM. <version>可省略,继承自spring-boot-dependencies
POM - Sensible resource filtering.
- Sensible plugin configuration (exec plugin, surefire, Git commit ID, shade).
- Sensible resource filtering for
application.properties
andapplication.yml
including profile-specific files (e.g.application-foo.properties
andapplication-foo.yml
) 自动去使用配置文件下的参数,例如server.port=9090 可指定端口为9090
On the last point: since the default config files accept Spring style placeholders (${…}
) the Maven filtering is changed to use @..@
placeholders (you can override that with a Maven property resource.delimiter
).
5、可使用@Configuration
注解导入基于XML的配置
If you absolutely must use XML based configuration, we recommend that you still start with a @Configuration
class. You can then use an additional @ImportResource
annotation to load XML configuration files.
6、启动时可以使用 --debug参数启动,可以查看debug级别日志,方便调试(例如在eclipse的启动参数里加入--debug即可)
If you need to find out what auto-configuration is currently being applied, and why, start your application with the --debug
switch. This will enable debug logs for a selection of core loggers and log an auto-configuration report to the console.
7、过滤一些不想注入的类
If you find that specific auto-configure classes are being applied that you don’t want, you can use the exclude attribute of @EnableAutoConfiguration
to disable them.
import org.springframework.boot.autoconfigure.*;import org.springframework.boot.autoconfigure.jdbc.*;import org.springframework.context.annotation.*;@Configuration@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})publicclass MyConfiguration {}
If the class is not on the classpath, you can use the excludeName
attribute of the annotation and specify the fully qualified name instead. Finally, you can also control the list of auto-configuration classes to exclude via the spring.autoconfigure.exclude
property.
@Configuration
, @EnableAutoConfiguration
和@ComponentScan三者之和
@SpringBootApplication
annotation is equivalent to using @Configuration
, @EnableAutoConfiguration
and @ComponentScan
with their default attributes9、热部署自动重启依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional><!-- optional=true,依赖不会传递-->
</dependency>
10、缓存优化
默认不开启,可以在配置文件配置,配置项可参考:https://github.com/spring-projects/spring-boot/blob/master/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java
Cache options are usually configured by settings in your application.properties
file. For example, Thymeleaf offers the spring.thymeleaf.cache
property. Rather than needing to set these properties manually, the spring-boot-devtools
module will automatically apply sensible development-time configuration.
Certain resources don’t necessarily need to trigger a restart when they are changed. For example, Thymeleaf templates can just be edited in-place. By default changing resources in /META-INF/maven
, /META-INF/resources
,/resources
,/static
,/public
or /templates
will not trigger a restart but will trigger a live reload. If you want to customize these exclusions you can use the spring.devtools.restart.exclude
property. For example, to exclude only /static
and /public
you would set the following:
spring.devtools.restart.exclude=static/**,public/**
if you want to keep those defaults and add additional exclusions, use the spring.devtools.restart.additional-exclude
property instead.
12、监视某些不在classpath下资源的变化时重启服务器
You may want your application to be restarted or reloaded when you make changes to files that are not on the classpath. To do so, use thespring.devtools.restart.additional-paths
property to configure additional paths to watch for changes. You can use the spring.devtools.restart.exclude
property described above to control whether changes beneath the additional paths will trigger a full restart or just a live reload.
13、设置不要自动重启
If you don’t want to use the restart feature you can disable it using the
spring.devtools.restart.enabled
property. In most cases you can set this in yourapplication.properties
(this will still initialize the restart classloader but it won’t watch for file changes).If you need to completely disable restart support, for example, because it doesn’t work with a specific library, you need to set a
System
property before callingSpringApplication.run(…)
. For example:publicstaticvoid main(String[] args) { System.setProperty("spring.devtools.restart.enabled", "false"); SpringApplication.run(MyApp.class, args);}待续。。。。。。。
- 【Spring Boot】Spring Boot
- spring boot
- spring boot
- spring-boot
- spring boot
- Spring Boot
- spring boot
- spring boot
- Spring Boot
- spring boot
- Spring Boot
- spring boot
- spring boot
- Spring Boot
- Spring-Boot
- spring boot
- Spring Boot
- spring-boot
- Linux内核编译,启动带linux内核的模拟器。
- 安装Notepad++
- java制造死锁
- leecode 解题总结:383. Ransom Note
- 可变数组 移除数据项
- spring boot
- leetCode练习(242)
- mysql-视图基础学习
- 2. Add Two Numbers
- 教你初步了解红黑树
- 使用Memcached实现Session共享
- Java开发中的23种设计模式详解(转)
- 四种内部类,(Inner Class)
- Xshell中的小键盘映射问题