spring boot 文档学习笔记day01
2018-06-18 02:48:46来源:未知 阅读 ()
1.在pom.xml中使用spring-boot-starter-parent的作用:
Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:
- Java 1.8 as the default compiler level.
- UTF-8 source encoding.
- A Dependency Management section, inherited from the spring-boot-dependencies pom, that manages the versions of common dependencies. This dependency management lets you omit <version> tags for those dependencies when used in your own pom.
- Sensible resource filtering.
- Sensible plugin configuration (exec plugin, Git commit ID, and shade).
- Sensible resource filtering for application.properties and application.yml including profile-specific files (for example, application-dev.properties and application-dev.yml)
2.pom.xml里面有哪些配置,太多了,网址:
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-dependencies/pom.xml
3.启动类的位置最好在最外层的包中:
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 is used to search for @Entity items.
Using a root package also lets the @ComponentScan annotation 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.
The following listing shows a typical layout:
com
+- example
+- myapplication
+- Application.java
|
+- customer
| +- Customer.java
| +- CustomerController.java
| +- CustomerService.java
| +- CustomerRepository.java
|
+- order
+- Order.java
+- OrderController.java
+- OrderService.java
+- OrderRepository.java
4.尽量使用java配置,避免使用xml配置
You need not put all your @Configuration
into a
single class. The @Import
annotation can be used to import additional configuration classes.
Alternatively, you can use @ComponentScan
to automatically pick up all Spring components, including @Configuration
classes.
If you absolutely must use XML based configuration, we recommend
that you still start with a @Configuration
class. You can then use
an @ImportResource
annotation to load XML configuration files.
5.自动配置
You need to opt-in to auto-configuration by
adding the @EnableAutoConfiguration
or @SpringBootApplication
annotations to one of your @Configuration
classes.,只添加到一个即可
6.排除不需要自动配置的类
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
或者
you can also control the list of auto-configuration classes to exclude by using the spring.autoconfigure.exclude
property.
7.Bean注入容器
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.) are automatically registered as Spring Beans.
8. @SpringBootApplication代替常用几个的注解
The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes
9.开发工具
The spring-boot-devtools module can be included in any project to provide additional development-time features.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
支持代码修改后重新加载启动,如果不需要:
If you do not want to use the restart feature, you can disable it by using the spring.devtools.restart.enabled property. In most cases, you can set this property in your application.properties (doing so still initializes the restart classloader, but it does not watch for file changes).
If you need to completely disable restart support (for example, because it does not work with a specific library), you need to set the spring.devtools.restart.enabled System property to false before calling SpringApplication.run(…?), as shown in the following example:
public static void main(String[] args) {
System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(MyApp.class, args);
}
在开过程中经常修改但是不想启动,application.properties里面设置指定的文件修改才重启:
#重启的文件resouces文件夹中新建文件restart.trigger并设置
spring.devtools.restart.trigger-file=restart.trigger
这样只有在restart.trigger这个文件更改时才重新启动
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- Spring系列.ApplicationContext接口 2020-06-11
- springboot2配置JavaMelody与springMVC配置JavaMelody 2020-06-11
- 给你一份超详细 Spring Boot 知识清单 2020-06-11
- SpringBoot 2.3 整合最新版 ShardingJdbc + Druid + MyBatis 2020-06-11
- 掌握SpringBoot-2.3的容器探针:实战篇 2020-06-11
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash